Skip to content

Commit e004d92

Browse files
authored
Handle arbitrary namespace identifiers in some SystemJS scenarios (#5321)
* Handle arbitrary identifiers when exporting function declarations * Update snapshots * Also use stringify for default exports for symmetry
1 parent d8b4aa6 commit e004d92

File tree

280 files changed

+474
-370
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

280 files changed

+474
-370
lines changed

src/ast/nodes/ExportDefaultDeclaration.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ export default class ExportDefaultDeclaration extends NodeBase {
146146
code.overwrite(
147147
this.start,
148148
declarationStart,
149-
`${cnst} ${this.variable.getName(getPropertyAccess)} = exports('${systemExportNames[0]}', `
149+
`${cnst} ${this.variable.getName(getPropertyAccess)} = exports(${JSON.stringify(
150+
systemExportNames[0]
151+
)}, `
150152
);
151153
code.appendRight(
152154
hasTrailingSemicolon ? this.end - 1 : this.end,

src/finalisers/system.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Bundle as MagicStringBundle } from 'magic-string';
22
import type { ChunkDependency, ChunkExports, ModuleDeclarations } from '../Chunk';
33
import type { NormalizedOutputOptions } from '../rollup/types';
44
import type { GenerateCodeSnippets } from '../utils/generateCodeSnippets';
5+
import { stringifyObjectKeyIfNeeded } from '../utils/identifierHelpers';
56
import { getHelpersBlock } from '../utils/interopHelpers';
67
import { MISSING_EXPORT_SHIM_VARIABLE } from '../utils/variableNames';
78
import type { FinaliserOptions } from './index';
@@ -145,7 +146,7 @@ function analyzeDependencies(
145146
}
146147
} else {
147148
const [key, value] = reexportedNames[0];
148-
setter.push(`exports('${key}',${_}${value});`);
149+
setter.push(`exports(${JSON.stringify(key)},${_}${value});`);
149150
}
150151
}
151152
setters.push(setter.join(`${n}${t}${t}${t}`));
@@ -204,11 +205,13 @@ function getExportsBlock(
204205
return '';
205206
}
206207
if (exports.length === 1) {
207-
return `exports('${exports[0].name}',${_}${exports[0].value});${n}${n}`;
208+
return `exports(${JSON.stringify(exports[0].name)},${_}${exports[0].value});${n}${n}`;
208209
}
209210
return (
210211
`exports({${n}` +
211-
exports.map(({ name, value }) => `${t}${name}:${_}${value}`).join(`,${n}`) +
212+
exports
213+
.map(({ name, value }) => `${t}${stringifyObjectKeyIfNeeded(name)}:${_}${value}`)
214+
.join(`,${n}`) +
212215
`${n}});${n}${n}`
213216
);
214217
}

test/chunking-form/samples/amd-id-auto-base-path-concat/_expected/system/some/where/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ System.register([], (function (exports, module) {
33
return {
44
execute: (function () {
55

6-
exports('getA', getA);
6+
exports("getA", getA);
77

88
function getA() {
99
return module.import('./generated-a.js');

test/chunking-form/samples/amd-id-auto-base-path/_expected/system/some/where/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ System.register([], (function (exports, module) {
33
return {
44
execute: (function () {
55

6-
exports('getA', getA);
6+
exports("getA", getA);
77

88
function getA() {
99
return module.import('./chunks/generated-a.js');

test/chunking-form/samples/amd-id-auto/_expected/system/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ System.register([], (function (exports, module) {
33
return {
44
execute: (function () {
55

6-
exports('getA', getA);
6+
exports("getA", getA);
77

88
function getA() {
99
return module.import('./generated-a.js');

test/chunking-form/samples/avoid-chunk-import-hoisting/_expected/system/generated-dep.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ System.register(['lib'], (function (exports) {
77
}],
88
execute: (function () {
99

10-
var dep = exports('d', 2 * value);
10+
var dep = exports("d", 2 * value);
1111

1212
})
1313
};

test/chunking-form/samples/basic-chunking/_expected/system/generated-dep2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ System.register([], (function (exports) {
33
return {
44
execute: (function () {
55

6-
exports('f', fn);
6+
exports("f", fn);
77

88
function fn$1 () {
99
console.log('lib2 fn');

test/chunking-form/samples/chunk-assigment-in-dynamic/_expected/system/generated-a.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ System.register(['./generated-c.js'], (function (exports) {
77
}],
88
execute: (function () {
99

10-
exports('A', A);
10+
exports("A", A);
1111

1212
function A() {
1313
return { icon: c.faPrint };

test/chunking-form/samples/chunk-assigment-in-dynamic/_expected/system/generated-b.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ System.register(['./generated-c.js'], (function (exports) {
77
}],
88
execute: (function () {
99

10-
exports('B', B);
10+
exports("B", B);
1111

1212
function B() {
1313
return { icon: c.faPrint };

test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/system/main2.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ System.register(['./main3.js', './main4.js'], (function (exports) {
99
}],
1010
execute: (function () {
1111

12-
var x = exports('x', x$1 + 1);
12+
var x = exports("x", x$1 + 1);
1313
console.log('shared1');
1414

15-
var y = exports('y', x$2 + 1);
15+
var y = exports("y", x$2 + 1);
1616
console.log('shared2');
1717

1818
})

0 commit comments

Comments
 (0)