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

Sort namespace object keys #4780

Merged
merged 4 commits into from Jan 2, 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
5 changes: 4 additions & 1 deletion src/ast/variables/NamespaceVariable.ts
Expand Up @@ -74,8 +74,11 @@ export default class NamespaceVariable extends Variable {
if (this.memberVariables) {
return this.memberVariables;
}

const memberVariables: { [name: string]: Variable } = Object.create(null);
for (const name of [...this.context.getExports(), ...this.context.getReexports()]) {
const sortedExports = [...this.context.getExports(), ...this.context.getReexports()].sort();

for (const name of sortedExports) {
if (name[0] !== '*' && name !== this.module.info.syntheticNamedExports) {
const exportedVariable = this.context.traceExport(name);
if (exportedVariable) {
Expand Down
Expand Up @@ -2,8 +2,8 @@ define(['./generated-geometry'], (function (geometry) { 'use strict';

var mod = /*#__PURE__*/Object.freeze({
__proto__: null,
volume: geometry.volume,
geometry: geometry.geometry
geometry: geometry.geometry,
volume: geometry.volume
});

console.log(mod);
Expand Down
Expand Up @@ -4,8 +4,8 @@ var geometry = require('./generated-geometry.js');

var mod = /*#__PURE__*/Object.freeze({
__proto__: null,
volume: geometry.volume,
geometry: geometry.geometry
geometry: geometry.geometry,
volume: geometry.volume
});

console.log(mod);
@@ -1,9 +1,9 @@
import { v as volume, g as geometry } from './generated-geometry.js';
import { g as geometry, v as volume } from './generated-geometry.js';

var mod = /*#__PURE__*/Object.freeze({
__proto__: null,
volume: volume,
geometry: geometry
geometry: geometry,
volume: volume
});

console.log(mod);
@@ -1,17 +1,17 @@
System.register(['./generated-geometry.js'], (function () {
'use strict';
var volume, geometry;
var geometry, volume;
return {
setters: [function (module) {
volume = module.v;
geometry = module.g;
volume = module.v;
}],
execute: (function () {

var mod = /*#__PURE__*/Object.freeze({
__proto__: null,
volume: volume,
geometry: geometry
geometry: geometry,
volume: volume
});

console.log(mod);
Expand Down
Expand Up @@ -20,8 +20,8 @@ define(['exports'], (function (exports) { 'use strict';

var dynamic1 = /*#__PURE__*/Object.freeze({
__proto__: null,
DYNAMIC_1: DYNAMIC_1,
DEP: DEP,
DYNAMIC_1: DYNAMIC_1,
DYNAMIC_2: DYNAMIC_2,
DYNAMIC_3: DYNAMIC_3
});
Expand Down
Expand Up @@ -20,8 +20,8 @@ const DYNAMIC_1 = 'DYNAMIC_1';

var dynamic1 = /*#__PURE__*/Object.freeze({
__proto__: null,
DYNAMIC_1: DYNAMIC_1,
DEP: DEP,
DYNAMIC_1: DYNAMIC_1,
DYNAMIC_2: DYNAMIC_2,
DYNAMIC_3: DYNAMIC_3
});
Expand Down
Expand Up @@ -18,8 +18,8 @@ const DYNAMIC_1 = 'DYNAMIC_1';

var dynamic1 = /*#__PURE__*/Object.freeze({
__proto__: null,
DYNAMIC_1: DYNAMIC_1,
DEP: DEP,
DYNAMIC_1: DYNAMIC_1,
DYNAMIC_2: DYNAMIC_2,
DYNAMIC_3: DYNAMIC_3
});
Expand Down
Expand Up @@ -25,8 +25,8 @@ System.register([], (function (exports) {

var dynamic1 = /*#__PURE__*/Object.freeze({
__proto__: null,
DYNAMIC_1: DYNAMIC_1,
DEP: DEP,
DYNAMIC_1: DYNAMIC_1,
DYNAMIC_2: DYNAMIC_2,
DYNAMIC_3: DYNAMIC_3
});
Expand Down
Expand Up @@ -15,8 +15,8 @@ define(['exports'], (function (exports) { 'use strict';

var dynamic1 = /*#__PURE__*/Object.freeze({
__proto__: null,
DYNAMIC_B: DYNAMIC_A,
DYNAMIC_A: DYNAMIC_B
DYNAMIC_A: DYNAMIC_B,
DYNAMIC_B: DYNAMIC_A
});

exports.dynamic1 = dynamic1;
Expand Down
Expand Up @@ -15,8 +15,8 @@ console.log('dynamic1');

var dynamic1 = /*#__PURE__*/Object.freeze({
__proto__: null,
DYNAMIC_B: DYNAMIC_A,
DYNAMIC_A: DYNAMIC_B
DYNAMIC_A: DYNAMIC_B,
DYNAMIC_B: DYNAMIC_A
});

exports.dynamic1 = dynamic1;
Expand Down
Expand Up @@ -13,8 +13,8 @@ console.log('dynamic1');

var dynamic1 = /*#__PURE__*/Object.freeze({
__proto__: null,
DYNAMIC_B: DYNAMIC_A,
DYNAMIC_A: DYNAMIC_B
DYNAMIC_A: DYNAMIC_B,
DYNAMIC_B: DYNAMIC_A
});

export { dynamic1 as a, dynamic2 as d };
Expand Up @@ -19,8 +19,8 @@ System.register([], (function (exports) {

var dynamic1 = /*#__PURE__*/Object.freeze({
__proto__: null,
DYNAMIC_B: DYNAMIC_A,
DYNAMIC_A: DYNAMIC_B
DYNAMIC_A: DYNAMIC_B,
DYNAMIC_B: DYNAMIC_A
});
exports('a', dynamic1);

Expand Down
Expand Up @@ -20,8 +20,8 @@ define(['exports'], (function (exports) { 'use strict';

var dynamic1 = /*#__PURE__*/Object.freeze({
__proto__: null,
DYNAMIC_1: DYNAMIC_1,
DEP: DEP,
DYNAMIC_1: DYNAMIC_1,
DYNAMIC_2: DYNAMIC_2,
DYNAMIC_3: DYNAMIC_3
});
Expand Down
Expand Up @@ -20,8 +20,8 @@ const DYNAMIC_1 = 'DYNAMIC_1';

var dynamic1 = /*#__PURE__*/Object.freeze({
__proto__: null,
DYNAMIC_1: DYNAMIC_1,
DEP: DEP,
DYNAMIC_1: DYNAMIC_1,
DYNAMIC_2: DYNAMIC_2,
DYNAMIC_3: DYNAMIC_3
});
Expand Down
Expand Up @@ -18,8 +18,8 @@ const DYNAMIC_1 = 'DYNAMIC_1';

var dynamic1 = /*#__PURE__*/Object.freeze({
__proto__: null,
DYNAMIC_1: DYNAMIC_1,
DEP: DEP,
DYNAMIC_1: DYNAMIC_1,
DYNAMIC_2: DYNAMIC_2,
DYNAMIC_3: DYNAMIC_3
});
Expand Down
Expand Up @@ -25,8 +25,8 @@ System.register([], (function (exports) {

var dynamic1 = /*#__PURE__*/Object.freeze({
__proto__: null,
DYNAMIC_1: DYNAMIC_1,
DEP: DEP,
DYNAMIC_1: DYNAMIC_1,
DYNAMIC_2: DYNAMIC_2,
DYNAMIC_3: DYNAMIC_3
});
Expand Down
Expand Up @@ -15,8 +15,8 @@ define(['exports'], (function (exports) { 'use strict';

var dynamic1 = /*#__PURE__*/Object.freeze({
__proto__: null,
DYNAMIC_B: DYNAMIC_A,
DYNAMIC_A: DYNAMIC_B
DYNAMIC_A: DYNAMIC_B,
DYNAMIC_B: DYNAMIC_A
});

exports.dynamic1 = dynamic1;
Expand Down
Expand Up @@ -15,8 +15,8 @@ console.log('dynamic1');

var dynamic1 = /*#__PURE__*/Object.freeze({
__proto__: null,
DYNAMIC_B: DYNAMIC_A,
DYNAMIC_A: DYNAMIC_B
DYNAMIC_A: DYNAMIC_B,
DYNAMIC_B: DYNAMIC_A
});

exports.dynamic1 = dynamic1;
Expand Down
Expand Up @@ -13,8 +13,8 @@ console.log('dynamic1');

var dynamic1 = /*#__PURE__*/Object.freeze({
__proto__: null,
DYNAMIC_B: DYNAMIC_A,
DYNAMIC_A: DYNAMIC_B
DYNAMIC_A: DYNAMIC_B,
DYNAMIC_B: DYNAMIC_A
});

export { dynamic1 as a, dynamic2 as d };
Expand Up @@ -19,8 +19,8 @@ System.register([], (function (exports) {

var dynamic1 = /*#__PURE__*/Object.freeze({
__proto__: null,
DYNAMIC_B: DYNAMIC_A,
DYNAMIC_A: DYNAMIC_B
DYNAMIC_A: DYNAMIC_B,
DYNAMIC_B: DYNAMIC_A
});
exports('a', dynamic1);

Expand Down
Expand Up @@ -20,8 +20,8 @@ define(['exports'], (function (exports) { 'use strict';

var dep$1 = /*#__PURE__*/_mergeNamespaces({
__proto__: null,
default: dep,
bar: bar
bar: bar,
default: dep
}, [dep]);

exports.dep = dep$1;
Expand Down
Expand Up @@ -20,8 +20,8 @@ const bar = 2;

var dep$1 = /*#__PURE__*/_mergeNamespaces({
__proto__: null,
default: dep,
bar: bar
bar: bar,
default: dep
}, [dep]);

exports.dep = dep$1;
Expand Up @@ -18,8 +18,8 @@ const bar = 2;

var dep$1 = /*#__PURE__*/_mergeNamespaces({
__proto__: null,
default: dep,
bar: bar
bar: bar,
default: dep
}, [dep]);

export { dep$1 as d };
Expand Up @@ -23,8 +23,8 @@ System.register([], (function (exports) {

var dep$1 = /*#__PURE__*/_mergeNamespaces({
__proto__: null,
default: dep,
bar: bar
bar: bar,
default: dep
}, [dep]);
exports('d', dep$1);

Expand Down
Expand Up @@ -23,8 +23,8 @@ define(['exports'], (function (exports) { 'use strict';

var ns = /*#__PURE__*/_mergeNamespaces({
__proto__: null,
foo: foo,
default: d
default: d,
foo: foo
}, [d]);

const stuff = 12;
Expand Down
Expand Up @@ -23,8 +23,8 @@ const foo = 100;

var ns = /*#__PURE__*/_mergeNamespaces({
__proto__: null,
foo: foo,
default: d
default: d,
foo: foo
}, [d]);

const stuff = 12;
Expand Down
Expand Up @@ -21,8 +21,8 @@ const foo = 100;

var ns = /*#__PURE__*/_mergeNamespaces({
__proto__: null,
foo: foo,
default: d
default: d,
foo: foo
}, [d]);

const stuff = 12;
Expand Down
Expand Up @@ -26,8 +26,8 @@ System.register([], (function (exports) {

var ns = /*#__PURE__*/_mergeNamespaces({
__proto__: null,
foo: foo,
default: d
default: d,
foo: foo
}, [d]);

const stuff = 12;
Expand Down
Expand Up @@ -36,8 +36,8 @@ define(['exports'], (function (exports) { 'use strict';
__proto__: null,
bar: bar,
default: dep,
synthetic: synthetic$1,
foo: foo
foo: foo,
synthetic: synthetic$1
}, [synthetic]);

exports.dep = dep$1;
Expand Down
Expand Up @@ -36,8 +36,8 @@ var dep$1 = /*#__PURE__*/_mergeNamespaces({
__proto__: null,
bar: bar,
default: dep,
synthetic: synthetic$1,
foo: foo
foo: foo,
synthetic: synthetic$1
}, [synthetic]);

exports.dep = dep$1;
Expand Up @@ -34,8 +34,8 @@ var dep$1 = /*#__PURE__*/_mergeNamespaces({
__proto__: null,
bar: bar,
default: dep,
synthetic: synthetic$1,
foo: foo
foo: foo,
synthetic: synthetic$1
}, [synthetic]);

export { dep$1 as dep };
Expand Up @@ -39,8 +39,8 @@ System.register([], (function (exports) {
__proto__: null,
bar: bar,
default: dep,
synthetic: synthetic$1,
foo: foo
foo: foo,
synthetic: synthetic$1
}, [synthetic]);
exports('dep', dep$1);

Expand Down
4 changes: 2 additions & 2 deletions test/form/samples/export-internal-namespace-as/_expected.js
Expand Up @@ -5,8 +5,8 @@ const bar = 'bar2';

var dep2 = /*#__PURE__*/Object.freeze({
__proto__: null,
foo: foo,
bar: bar
bar: bar,
foo: foo
});

console.log(foo$1);
Expand Down
4 changes: 2 additions & 2 deletions test/form/samples/export-namespace-as/_expected/amd.js
Expand Up @@ -5,8 +5,8 @@ define(['exports'], (function (exports) { 'use strict';

var dep = /*#__PURE__*/Object.freeze({
__proto__: null,
foo: foo,
bar: bar
bar: bar,
foo: foo
});

exports.dep = dep;
Expand Down