From fa521cbddd278d6753dc35c9e8d9fb1148094740 Mon Sep 17 00:00:00 2001 From: Brian Donovan Date: Sun, 20 Mar 2016 11:13:26 -0700 Subject: [PATCH] Fix edge case for non-exported variable declaration aliases for exported globals. Closes #560. --- src/Module.js | 2 +- .../import-named-exported-global-with-alias/_config.js | 6 ++++++ .../_expected/amd.js | 5 +++++ .../_expected/cjs.js | 2 ++ .../_expected/es6.js | 0 .../_expected/iife.js | 6 ++++++ .../_expected/umd.js | 9 +++++++++ .../import-named-exported-global-with-alias/browser.js | 1 + .../form/import-named-exported-global-with-alias/main.js | 2 ++ 9 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/form/import-named-exported-global-with-alias/_config.js create mode 100644 test/form/import-named-exported-global-with-alias/_expected/amd.js create mode 100644 test/form/import-named-exported-global-with-alias/_expected/cjs.js create mode 100644 test/form/import-named-exported-global-with-alias/_expected/es6.js create mode 100644 test/form/import-named-exported-global-with-alias/_expected/iife.js create mode 100644 test/form/import-named-exported-global-with-alias/_expected/umd.js create mode 100644 test/form/import-named-exported-global-with-alias/browser.js create mode 100644 test/form/import-named-exported-global-with-alias/main.js diff --git a/src/Module.js b/src/Module.js index 4b2e7d4..9be65dc 100644 --- a/src/Module.js +++ b/src/Module.js @@ -189,7 +189,7 @@ export default class Module { const declaration = this.declarations[ name ]; const statement = declaration.statement; - if ( statement.node.type !== 'VariableDeclaration' ) return; + if ( !statement || statement.node.type !== 'VariableDeclaration' ) return; const init = statement.node.declarations[0].init; if ( !init || init.type === 'FunctionExpression' ) return; diff --git a/test/form/import-named-exported-global-with-alias/_config.js b/test/form/import-named-exported-global-with-alias/_config.js new file mode 100644 index 0000000..85b39fe --- /dev/null +++ b/test/form/import-named-exported-global-with-alias/_config.js @@ -0,0 +1,6 @@ +module.exports = { + description: 'allow globals to be exported and imported', + options: { + moduleName: 'doc' + } +}; diff --git a/test/form/import-named-exported-global-with-alias/_expected/amd.js b/test/form/import-named-exported-global-with-alias/_expected/amd.js new file mode 100644 index 0000000..ec759b1 --- /dev/null +++ b/test/form/import-named-exported-global-with-alias/_expected/amd.js @@ -0,0 +1,5 @@ +define(function () { 'use strict'; + + + +}); \ No newline at end of file diff --git a/test/form/import-named-exported-global-with-alias/_expected/cjs.js b/test/form/import-named-exported-global-with-alias/_expected/cjs.js new file mode 100644 index 0000000..eb109ab --- /dev/null +++ b/test/form/import-named-exported-global-with-alias/_expected/cjs.js @@ -0,0 +1,2 @@ +'use strict'; + diff --git a/test/form/import-named-exported-global-with-alias/_expected/es6.js b/test/form/import-named-exported-global-with-alias/_expected/es6.js new file mode 100644 index 0000000..e69de29 diff --git a/test/form/import-named-exported-global-with-alias/_expected/iife.js b/test/form/import-named-exported-global-with-alias/_expected/iife.js new file mode 100644 index 0000000..f3d1016 --- /dev/null +++ b/test/form/import-named-exported-global-with-alias/_expected/iife.js @@ -0,0 +1,6 @@ +(function () { + 'use strict'; + + + +}()); \ No newline at end of file diff --git a/test/form/import-named-exported-global-with-alias/_expected/umd.js b/test/form/import-named-exported-global-with-alias/_expected/umd.js new file mode 100644 index 0000000..f3395b7 --- /dev/null +++ b/test/form/import-named-exported-global-with-alias/_expected/umd.js @@ -0,0 +1,9 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define(factory) : + (factory()); +}(this, function () { 'use strict'; + + + +})); \ No newline at end of file diff --git a/test/form/import-named-exported-global-with-alias/browser.js b/test/form/import-named-exported-global-with-alias/browser.js new file mode 100644 index 0000000..a7aab36 --- /dev/null +++ b/test/form/import-named-exported-global-with-alias/browser.js @@ -0,0 +1 @@ +export { document }; diff --git a/test/form/import-named-exported-global-with-alias/main.js b/test/form/import-named-exported-global-with-alias/main.js new file mode 100644 index 0000000..5d3739c --- /dev/null +++ b/test/form/import-named-exported-global-with-alias/main.js @@ -0,0 +1,2 @@ +import { document } from './browser.js'; +var d = document;