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

Handle arbitrary namespace identifiers in some SystemJS scenarios #5321

Merged
merged 3 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/ast/nodes/ExportDefaultDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ export default class ExportDefaultDeclaration extends NodeBase {
code.overwrite(
this.start,
declarationStart,
`${cnst} ${this.variable.getName(getPropertyAccess)} = exports('${systemExportNames[0]}', `
`${cnst} ${this.variable.getName(getPropertyAccess)} = exports(${JSON.stringify(
systemExportNames[0]
)}, `
);
code.appendRight(
hasTrailingSemicolon ? this.end - 1 : this.end,
Expand Down
9 changes: 6 additions & 3 deletions src/finalisers/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Bundle as MagicStringBundle } from 'magic-string';
import type { ChunkDependency, ChunkExports, ModuleDeclarations } from '../Chunk';
import type { NormalizedOutputOptions } from '../rollup/types';
import type { GenerateCodeSnippets } from '../utils/generateCodeSnippets';
import { stringifyObjectKeyIfNeeded } from '../utils/identifierHelpers';
import { getHelpersBlock } from '../utils/interopHelpers';
import { MISSING_EXPORT_SHIM_VARIABLE } from '../utils/variableNames';
import type { FinaliserOptions } from './index';
Expand Down Expand Up @@ -145,7 +146,7 @@ function analyzeDependencies(
}
} else {
const [key, value] = reexportedNames[0];
setter.push(`exports('${key}',${_}${value});`);
setter.push(`exports(${JSON.stringify(key)},${_}${value});`);
}
}
setters.push(setter.join(`${n}${t}${t}${t}`));
Expand Down Expand Up @@ -204,11 +205,13 @@ function getExportsBlock(
return '';
}
if (exports.length === 1) {
return `exports('${exports[0].name}',${_}${exports[0].value});${n}${n}`;
return `exports(${JSON.stringify(exports[0].name)},${_}${exports[0].value});${n}${n}`;
}
return (
`exports({${n}` +
exports.map(({ name, value }) => `${t}${name}:${_}${value}`).join(`,${n}`) +
exports
.map(({ name, value }) => `${t}${stringifyObjectKeyIfNeeded(name)}:${_}${value}`)
.join(`,${n}`) +
`${n}});${n}${n}`
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ System.register([], (function (exports, module) {
return {
execute: (function () {

exports('getA', getA);
exports("getA", getA);

function getA() {
return module.import('./generated-a.js');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ System.register([], (function (exports, module) {
return {
execute: (function () {

exports('getA', getA);
exports("getA", getA);

function getA() {
return module.import('./chunks/generated-a.js');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ System.register([], (function (exports, module) {
return {
execute: (function () {

exports('getA', getA);
exports("getA", getA);

function getA() {
return module.import('./generated-a.js');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ System.register(['lib'], (function (exports) {
}],
execute: (function () {

var dep = exports('d', 2 * value);
var dep = exports("d", 2 * value);

})
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ System.register([], (function (exports) {
return {
execute: (function () {

exports('f', fn);
exports("f", fn);

function fn$1 () {
console.log('lib2 fn');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ System.register(['./generated-c.js'], (function (exports) {
}],
execute: (function () {

exports('A', A);
exports("A", A);

function A() {
return { icon: c.faPrint };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ System.register(['./generated-c.js'], (function (exports) {
}],
execute: (function () {

exports('B', B);
exports("B", B);

function B() {
return { icon: c.faPrint };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ System.register(['./main3.js', './main4.js'], (function (exports) {
}],
execute: (function () {

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

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

})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ System.register(['./generated-main1.js'], (function (exports) {
'use strict';
return {
setters: [function (module) {
exports('ItemOne', module.a);
exports("ItemOne", module.a);
}],
execute: (function () {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ System.register([], (function (exports) {
return {
execute: (function () {

exports('e', emptyFunction);
exports("e", emptyFunction);

function emptyFunction() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ System.register(['./generated-shared.js'], (function (exports) {
commonjsGlobal.fn = d => d + 1;
var cjs = commonjsGlobal.fn;

var main1 = exports('default', shared.map(cjs));
var main1 = exports("default", shared.map(cjs));

})
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ System.register(['./generated-shared.js'], (function (exports) {
}],
execute: (function () {

var main2 = exports('default', shared.map(d => d + 2));
var main2 = exports("default", shared.map(d => d + 2));

})
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ System.register([], (function (exports) {
return {
execute: (function () {

var value = exports('v', 42);
var value = exports("v", 42);
const x = exports("x", 3);

})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([],(function(exports){'use strict';return{execute:(function(){exports('f',fn);function fn$1 () {
System.register([],(function(exports){'use strict';return{execute:(function(){exports("f",fn);function fn$1 () {
console.log('lib2 fn');
}function fn () {
fn$1();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ System.register([], (function (exports) {
return {
execute: (function () {

exports('f', fn);
exports("f", fn);

function fn$1 () {
console.log('lib2 fn');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ System.register(['external'], (function (exports) {
'use strict';
return {
setters: [function (module) {
exports('dep', module.asdf);
exports("dep", module.asdf);
}],
execute: (function () {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ System.register(['./main1.js', 'external'], (function (exports) {
'use strict';
return {
setters: [null, function (module) {
exports('dep', module.asdf);
exports("dep", module.asdf);
}],
execute: (function () {

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ System.register(['starexternal1', 'external1', './generated-dep.js', 'starextern
}
exports(setter);
}, function (module) {
exports('e', module.e);
exports("e", module.e);
}, function (module) {
exports('dep', module.d);
exports("dep", module.d);
}, null, null],
execute: (function () {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ System.register(['./generated-dep.js', 'external2', 'starexternal2'], (function
};
return {
setters: [function (module) {
exports('dep', module.d);
exports("dep", module.d);
}, function (module) {
exports('e', module.e);
exports("e", module.e);
}, function (module) {
var setter = {};
for (var name in module) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ System.register(['./generated-main1.js'], (function (exports) {
'use strict';
return {
setters: [function (module) {
exports('p', module.a);
exports("p", module.a);
}],
execute: (function () {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ System.register(['./generated-main1.js'], (function (exports) {
'use strict';
return {
setters: [function (module) {
exports('p', module.p);
exports("p", module.p);
}],
execute: (function () {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ System.register(['./main2.js'], (function (exports) {
'use strict';
return {
setters: [function (module) {
exports('p', module.p2);
exports("p", module.p2);
}],
execute: (function () {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ System.register(['./generated-main3.js'], (function (exports) {
'use strict';
return {
setters: [function (module) {
exports('p', module.a);
exports("p", module.a);
}],
execute: (function () {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ System.register(['./generated-main3.js'], (function (exports) {
'use strict';
return {
setters: [function (module) {
exports('C', module.C);
exports("C", module.C);
}],
execute: (function () {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ System.register(['./generated-lib1.js', './generated-lib2.js'], (function (expor
'use strict';
return {
setters: [function (module) {
exports('lib1', module.l);
exports("lib1", module.l);
}, null],
execute: (function () {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ System.register(['./other.js'], (function (exports) {
}],
execute: (function () {

var main = exports('default', other + "extended");
var main = exports("default", other + "extended");

})
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ System.register(['./generated-shared.js'], (function (exports) {
}],
execute: (function () {

var main1 = exports('default', data.map(d => d + 1));
var main1 = exports("default", data.map(d => d + 1));

})
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ System.register(['./generated-shared.js'], (function (exports) {
}],
execute: (function () {

var main2 = exports('default', data.map(d => d + 2));
var main2 = exports("default", data.map(d => d + 2));

})
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ System.register(['./generated-main.js'], (function (exports) {
}],
execute: (function () {

exports('mult', mult);
exports("mult", mult);

function mult (num) {
return num + multiplier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ System.register([], (function (exports) {
return {
execute: (function () {

var separate = exports('default', 'separate');
var separate = exports("default", 'separate');
const x = exports("x", 2);
console.log('separate');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ System.register([], (function (exports) {
return {
execute: (function () {

var entry = exports('default', 42);
var entry = exports("default", 42);

})
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ System.register([], (function (exports) {
return {
execute: (function () {

var other = exports('default', 42);
var other = exports("default", 42);

})
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ System.register([], (function (exports, module) {
return {
execute: (function () {

var main = exports('default', Promise.all([module.import('./entry.js'), module.import('./generated-other.js')]));
var main = exports("default", Promise.all([module.import('./entry.js'), module.import('./generated-other.js')]));

})
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ System.register([], (function (exports) {
}

const __moduleExports = { foo: 'bar' };
var lib = exports('default', 'baz');
var lib = exports("default", 'baz');

var lib$1 = /*#__PURE__*/_mergeNamespaces({
__proto__: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ System.register(['./main.js'], (function (exports) {
'use strict';
return {
setters: [function (module) {
exports('value', module.s);
exports("value", module.s);
}],
execute: (function () {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ System.register(['./chunks/main.js'], (function (exports) {
'use strict';
return {
setters: [function (module) {
exports('promise', module.p);
exports("promise", module.p);
}],
execute: (function () {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ System.register([], (function (exports, module) {
return {
execute: (function () {

var value = exports('v', 42);
var value = exports("v", 42);

const promise = exports("p", module.import('./generated-dynamic.js').then(result => console.log('main', result, value)));

Expand Down