Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of sectioned source maps missing 'names' array #29

Merged

Conversation

RandomByte
Copy link
Contributor

@RandomByte RandomByte commented Oct 10, 2023

Even though the names array is seen as required, normalize it to an empty array if omitted

Currently, trace-mapping will throw with an exception "Cannot read properties of undefined (reading 'length')" in case no 'names' array is provided.

Copy link
Owner

@jridgewell jridgewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK just like for regular source maps, the names array can be omitted for maps in sectioned/index source maps.

This is incorrect. Each map in a section is an embedded complete source map object, and a source map object has a non-optional names array.

src/any-map.ts Outdated
@@ -111,7 +111,9 @@ function addSection(
const { resolvedSources, sourcesContent: contents } = map;

append(sources, resolvedSources);
append(names, map.names);
if (map.names) {
append(names, map.names);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing this here, we can normalize the map to always contain a names array. map is just a TraceMap instance, so we just need to update

this.names = names;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Even though the 'names' array is seen as required, normalize it to an
empty array if omitted

Currently, trace-mapping will throw with an exception
"Cannot read properties of undefined (reading 'length')"
in case no 'names' array is provided.
@RandomByte RandomByte force-pushed the sectioned-source-map-omit-names-array branch from f60214e to 65818ba Compare October 11, 2023 08:02
@RandomByte
Copy link
Contributor Author

RandomByte commented Oct 11, 2023

Thanks for the fast feedback! From reading the spec, it was not entirely clear to me which fields where required, but I see now that only few are declared as "optional".

I updated the PR as proposed and amended the existing commit. We'll also fix our index source maps to always include a names array 👍

@jridgewell jridgewell merged commit 5a8583c into jridgewell:main Oct 11, 2023
d3xter666 added a commit to SAP/ui5-builder that referenced this pull request Mar 5, 2024
JIRA: CPOUI5FOUNDATION-802

jridgewell/trace-mapping#29 got resolved and
merged, but Terser still have not updated their dependency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants