Browse Source

quote reserved properties in legacy mode

legacy-quote-reserved-properties
Rich Harris 8 years ago
parent
commit
81bf060969
  1. 3
      src/Declaration.js
  2. 2
      src/utils/makeLegalIdentifier.js
  3. 7
      test/form/legacy-reified-namespace/_config.js
  4. 14
      test/form/legacy-reified-namespace/_expected/amd.js
  5. 12
      test/form/legacy-reified-namespace/_expected/cjs.js
  6. 10
      test/form/legacy-reified-namespace/_expected/es.js
  7. 15
      test/form/legacy-reified-namespace/_expected/iife.js
  8. 18
      test/form/legacy-reified-namespace/_expected/umd.js
  9. 3
      test/form/legacy-reified-namespace/main.js
  10. 3
      test/form/legacy-reified-namespace/namespace.js
  11. 2
      test/form/legacy/_config.js

3
src/Declaration.js

@ -1,5 +1,5 @@
import { blank, forOwn, keys } from './utils/object.js';
import makeLegalIdentifier from './utils/makeLegalIdentifier.js';
import makeLegalIdentifier, { reservedWords } from './utils/makeLegalIdentifier.js';
import { UNKNOWN } from './ast/values.js';
export default class Declaration {
@ -83,6 +83,7 @@ export class SyntheticNamespaceDeclaration {
return `${indentString}get ${name} () { return ${original.getName( es )}; }`;
}
if ( legacy && ~reservedWords.indexOf( name ) ) name = `'${name}'`;
return `${indentString}${name}: ${original.getName( es )}`;
});

2
src/utils/makeLegalIdentifier.js

@ -1,6 +1,6 @@
import { blank } from './object.js';
const reservedWords = 'break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public'.split( ' ' );
export const reservedWords = 'break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public'.split( ' ' );
const builtins = 'Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl'.split( ' ' );
const blacklisted = blank();

7
test/form/legacy-reified-namespace/_config.js

@ -0,0 +1,7 @@
module.exports = {
description: 'quotes reserved words in object literals',
options: {
moduleName: 'myBundle',
legacy: true
}
};

14
test/form/legacy-reified-namespace/_expected/amd.js

@ -0,0 +1,14 @@
define(function () { 'use strict';
const _typeof = 'typeof';
const foo = 1;
var namespace = (Object.freeze || Object)({
'typeof': _typeof,
foo: foo
});
console.log( namespace );
});

12
test/form/legacy-reified-namespace/_expected/cjs.js

@ -0,0 +1,12 @@
'use strict';
const _typeof = 'typeof';
const foo = 1;
var namespace = (Object.freeze || Object)({
'typeof': _typeof,
foo: foo
});
console.log( namespace );

10
test/form/legacy-reified-namespace/_expected/es.js

@ -0,0 +1,10 @@
const _typeof = 'typeof';
const foo = 1;
var namespace = (Object.freeze || Object)({
'typeof': _typeof,
foo: foo
});
console.log( namespace );

15
test/form/legacy-reified-namespace/_expected/iife.js

@ -0,0 +1,15 @@
(function () {
'use strict';
const _typeof = 'typeof';
const foo = 1;
var namespace = (Object.freeze || Object)({
'typeof': _typeof,
foo: foo
});
console.log( namespace );
}());

18
test/form/legacy-reified-namespace/_expected/umd.js

@ -0,0 +1,18 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
(factory());
}(this, (function () { 'use strict';
const _typeof = 'typeof';
const foo = 1;
var namespace = (Object.freeze || Object)({
'typeof': _typeof,
foo: foo
});
console.log( namespace );
})));

3
test/form/legacy-reified-namespace/main.js

@ -0,0 +1,3 @@
import * as namespace from './namespace.js';
console.log( namespace );

3
test/form/legacy-reified-namespace/namespace.js

@ -0,0 +1,3 @@
const _typeof = 'typeof';
export { _typeof as typeof };
export const foo = 1;

2
test/form/legacy/_config.js

@ -1,7 +1,7 @@
module.exports = {
description: 'supports environments without Object.freeze, Object.defined',
options: {
moduleName: 'myBundle',
moduleName: 'myBundle',
legacy: true
}
};

Loading…
Cancel
Save