Skip to content

Commit

Permalink
Sort namespace object keys (#4780)
Browse files Browse the repository at this point in the history
* Sort namespace object keys

* Fix existing tests

* add test

Co-authored-by: Lukas Taegert-Atkinson <lukastaegert@users.noreply.github.com>
  • Loading branch information
dnalborczyk and lukastaegert committed Jan 2, 2023
1 parent 08b61f5 commit f00b251
Show file tree
Hide file tree
Showing 62 changed files with 153 additions and 110 deletions.
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

0 comments on commit f00b251

Please sign in to comment.