Browse Source

FIX: test for legacy; remove Object.define for legacy

legacy-quote-reserved-properties
1111hui 8 years ago
parent
commit
d5997f36c3
  1. 1
      bin/src/index.js
  2. 1
      bin/src/runRollup.js
  3. 2
      src/finalisers/amd.js
  4. 2
      src/finalisers/cjs.js
  5. 2
      src/finalisers/umd.js
  6. 3
      test/form/legacy/_config.js
  7. 17
      test/form/legacy/_expected/amd.js
  8. 15
      test/form/legacy/_expected/cjs.js
  9. 14
      test/form/legacy/_expected/es.js
  10. 19
      test/form/legacy/_expected/iife.js
  11. 23
      test/form/legacy/_expected/umd.js
  12. 6
      test/form/legacy/main.js
  13. 3
      test/form/legacy/namespace.js

1
bin/src/index.js

@ -16,6 +16,7 @@ const command = minimist( process.argv.slice( 2 ), {
g: 'globals', g: 'globals',
h: 'help', h: 'help',
i: 'input', i: 'input',
l: 'legacy',
m: 'sourcemap', m: 'sourcemap',
n: 'name', n: 'name',
o: 'output', o: 'output',

1
bin/src/runRollup.js

@ -105,6 +105,7 @@ const equivalents = {
indent: 'indent', indent: 'indent',
input: 'entry', input: 'entry',
intro: 'intro', intro: 'intro',
legacy: 'legacy',
name: 'moduleName', name: 'moduleName',
output: 'dest', output: 'dest',
outro: 'outro', outro: 'outro',

2
src/finalisers/amd.js

@ -27,7 +27,7 @@ export default function amd ( bundle, magicString, { exportMode, indentString, i
const exportBlock = getExportBlock( bundle.entryModule, exportMode ); const exportBlock = getExportBlock( bundle.entryModule, exportMode );
if ( exportBlock ) magicString.append( '\n\n' + exportBlock ); if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
if ( exportMode === 'named' ) magicString.append( `\n\n${esModuleExport}` ); if ( exportMode === 'named' && options.legacy !== true ) magicString.append( `\n\n${esModuleExport}` );
if ( options.outro ) magicString.append( `\n${options.outro}` ); if ( options.outro ) magicString.append( `\n${options.outro}` );
return magicString return magicString

2
src/finalisers/cjs.js

@ -3,7 +3,7 @@ import esModuleExport from './shared/esModuleExport.js';
export default function cjs ( bundle, magicString, { exportMode, intro }, options ) { export default function cjs ( bundle, magicString, { exportMode, intro }, options ) {
intro = ( options.useStrict === false ? intro : `'use strict';\n\n${intro}` ) + intro = ( options.useStrict === false ? intro : `'use strict';\n\n${intro}` ) +
( exportMode === 'named' ? `${esModuleExport}\n\n` : '' ); ( exportMode === 'named' && options.legacy !== true ? `${esModuleExport}\n\n` : '' );
let needsInterop = false; let needsInterop = false;

2
src/finalisers/umd.js

@ -73,7 +73,7 @@ export default function umd ( bundle, magicString, { exportMode, indentString, i
const exportBlock = getExportBlock( bundle.entryModule, exportMode ); const exportBlock = getExportBlock( bundle.entryModule, exportMode );
if ( exportBlock ) magicString.append( '\n\n' + exportBlock ); if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
if ( exportMode === 'named' ) magicString.append( `\n\n${esModuleExport}` ); if ( exportMode === 'named' && options.legacy !== true ) magicString.append( `\n\n${esModuleExport}` );
if ( options.outro ) magicString.append( `\n${options.outro}` ); if ( options.outro ) magicString.append( `\n${options.outro}` );
return magicString return magicString

3
test/form/legacy/_config.js

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

17
test/form/legacy/_expected/amd.js

@ -1,13 +1,20 @@
define(function () { 'use strict'; define(['exports'], function (exports) { 'use strict';
const foo = 42; const foo = 1;
const bar = 2;
var namespace = (Object.freeze || Object)({ var namespace = (Object.freeze || Object)({
foo: foo foo: foo,
bar: bar
}); });
const x = 'foo'; console.log( Object.keys( namespace ) );
assert.equal( namespace[x], 42 );
const a = 1;
const b = 2;
exports.a = a;
exports.b = b;
}); });

15
test/form/legacy/_expected/cjs.js

@ -1,11 +1,18 @@
'use strict'; 'use strict';
const foo = 42; const foo = 1;
const bar = 2;
var namespace = (Object.freeze || Object)({ var namespace = (Object.freeze || Object)({
foo: foo foo: foo,
bar: bar
}); });
const x = 'foo'; console.log( Object.keys( namespace ) );
assert.equal( namespace[x], 42 );
const a = 1;
const b = 2;
exports.a = a;
exports.b = b;

14
test/form/legacy/_expected/es.js

@ -1,9 +1,15 @@
const foo = 42; const foo = 1;
const bar = 2;
var namespace = (Object.freeze || Object)({ var namespace = (Object.freeze || Object)({
foo: foo foo: foo,
bar: bar
}); });
const x = 'foo'; console.log( Object.keys( namespace ) );
assert.equal( namespace[x], 42 );
const a = 1;
const b = 2;
export { a, b };

19
test/form/legacy/_expected/iife.js

@ -1,14 +1,21 @@
(function () { (function (exports) {
'use strict'; 'use strict';
const foo = 42; const foo = 1;
const bar = 2;
var namespace = (Object.freeze || Object)({ var namespace = (Object.freeze || Object)({
foo: foo foo: foo,
bar: bar
}); });
const x = 'foo'; console.log( Object.keys( namespace ) );
assert.equal( namespace[x], 42 );
}()); const a = 1;
const b = 2;
exports.a = a;
exports.b = b;
}((this.myBundle = this.myBundle || {})));

23
test/form/legacy/_expected/umd.js

@ -1,17 +1,24 @@
(function (global, factory) { (function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(factory) : typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory()); (factory((global.myBundle = global.myBundle || {})));
}(this, (function () { 'use strict'; }(this, (function (exports) { 'use strict';
const foo = 42; const foo = 1;
const bar = 2;
var namespace = (Object.freeze || Object)({ var namespace = (Object.freeze || Object)({
foo: foo foo: foo,
bar: bar
}); });
const x = 'foo'; console.log( Object.keys( namespace ) );
assert.equal( namespace[x], 42 );
const a = 1;
const b = 2;
exports.a = a;
exports.b = b;
}))); })));

6
test/form/legacy/main.js

@ -1,4 +1,6 @@
import * as namespace from './namespace.js'; import * as namespace from './namespace.js';
const x = 'foo'; console.log( Object.keys( namespace ) );
assert.equal( namespace[x], 42 );
export const a = 1;
export const b = 2;

3
test/form/legacy/namespace.js

@ -1 +1,2 @@
export const foo = 42; export const foo = 1;
export const bar = 2;

Loading…
Cancel
Save