jass 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +47 -0
- data/README.md +45 -0
- data/lib/jass.rb +55 -0
- data/lib/jass/base.rb +141 -0
- data/lib/jass/bundle_processor.rb +28 -0
- data/lib/jass/compiler.rb +112 -0
- data/lib/jass/dependency.rb +14 -0
- data/lib/jass/errors.rb +29 -0
- data/lib/jass/es6_processor.rb +17 -0
- data/lib/jass/function.rb +13 -0
- data/lib/jass/global_directive_processor.rb +12 -0
- data/lib/jass/plugin.rb +13 -0
- data/lib/jass/railtie.rb +12 -0
- data/lib/jass/version.rb +3 -0
- data/vendor/node_modules/@types/acorn/index.d.ts +256 -0
- data/vendor/node_modules/@types/acorn/package.json +29 -0
- data/vendor/node_modules/@types/estree/index.d.ts +546 -0
- data/vendor/node_modules/@types/estree/package.json +22 -0
- data/vendor/node_modules/acorn-dynamic-import/lib/index.js +17 -0
- data/vendor/node_modules/acorn-dynamic-import/lib/inject.js +72 -0
- data/vendor/node_modules/acorn-dynamic-import/lib/walk.js +22 -0
- data/vendor/node_modules/acorn-dynamic-import/package.json +45 -0
- data/vendor/node_modules/acorn-dynamic-import/src/index.js +4 -0
- data/vendor/node_modules/acorn-dynamic-import/src/inject.js +52 -0
- data/vendor/node_modules/acorn-dynamic-import/src/walk.js +12 -0
- data/vendor/node_modules/acorn-es7-plugin/acorn-es7-plugin.js +17 -0
- data/vendor/node_modules/acorn-es7-plugin/acorn-v3.js +333 -0
- data/vendor/node_modules/acorn-es7-plugin/acorn-v4.js +194 -0
- data/vendor/node_modules/acorn-es7-plugin/package.json +29 -0
- data/vendor/node_modules/acorn-jsx/index.js +3 -0
- data/vendor/node_modules/acorn-jsx/inject.js +449 -0
- data/vendor/node_modules/acorn-jsx/package.json +28 -0
- data/vendor/node_modules/acorn-jsx/xhtml.js +255 -0
- data/vendor/node_modules/acorn/bin/_acorn.js +69 -0
- data/vendor/node_modules/acorn/bin/acorn +4 -0
- data/vendor/node_modules/acorn/bin/run_test262.js +22 -0
- data/vendor/node_modules/acorn/bin/test262.whitelist +409 -0
- data/vendor/node_modules/acorn/dist/acorn.es.js +5305 -0
- data/vendor/node_modules/acorn/dist/acorn.js +5336 -0
- data/vendor/node_modules/acorn/dist/acorn_loose.es.js +1412 -0
- data/vendor/node_modules/acorn/dist/acorn_loose.js +1422 -0
- data/vendor/node_modules/acorn/dist/walk.es.js +419 -0
- data/vendor/node_modules/acorn/dist/walk.js +439 -0
- data/vendor/node_modules/acorn/package.json +56 -0
- data/vendor/node_modules/ansi-styles/index.js +165 -0
- data/vendor/node_modules/ansi-styles/package.json +56 -0
- data/vendor/node_modules/arr-diff/index.js +58 -0
- data/vendor/node_modules/arr-diff/package.json +49 -0
- data/vendor/node_modules/arr-flatten/index.js +22 -0
- data/vendor/node_modules/arr-flatten/package.json +76 -0
- data/vendor/node_modules/array-unique/index.js +28 -0
- data/vendor/node_modules/array-unique/package.json +37 -0
- data/vendor/node_modules/braces/index.js +399 -0
- data/vendor/node_modules/braces/package.json +83 -0
- data/vendor/node_modules/buble/bin/buble +24 -0
- data/vendor/node_modules/buble/bin/handleError.js +58 -0
- data/vendor/node_modules/buble/bin/runBuble.js +150 -0
- data/vendor/node_modules/buble/bin/showHelp.js +16 -0
- data/vendor/node_modules/buble/dist/buble-browser-deps.umd.js +14857 -0
- data/vendor/node_modules/buble/dist/buble-browser.cjs.js +9941 -0
- data/vendor/node_modules/buble/dist/buble-browser.es.js +9933 -0
- data/vendor/node_modules/buble/dist/buble.cjs.js +9433 -0
- data/vendor/node_modules/buble/dist/buble.es.js +9425 -0
- data/vendor/node_modules/buble/package.json +74 -0
- data/vendor/node_modules/buble/register.js +90 -0
- data/vendor/node_modules/buble/src/index.js +98 -0
- data/vendor/node_modules/buble/src/program/BlockStatement.js +373 -0
- data/vendor/node_modules/buble/src/program/Node.js +112 -0
- data/vendor/node_modules/buble/src/program/Program.js +74 -0
- data/vendor/node_modules/buble/src/program/Scope.js +116 -0
- data/vendor/node_modules/buble/src/program/extractNames.js +35 -0
- data/vendor/node_modules/buble/src/program/keys.js +4 -0
- data/vendor/node_modules/buble/src/program/types/ArrayExpression.js +70 -0
- data/vendor/node_modules/buble/src/program/types/ArrowFunctionExpression.js +52 -0
- data/vendor/node_modules/buble/src/program/types/AssignmentExpression.js +185 -0
- data/vendor/node_modules/buble/src/program/types/BinaryExpression.js +12 -0
- data/vendor/node_modules/buble/src/program/types/BreakStatement.js +26 -0
- data/vendor/node_modules/buble/src/program/types/CallExpression.js +104 -0
- data/vendor/node_modules/buble/src/program/types/ClassBody.js +237 -0
- data/vendor/node_modules/buble/src/program/types/ClassDeclaration.js +79 -0
- data/vendor/node_modules/buble/src/program/types/ClassExpression.js +51 -0
- data/vendor/node_modules/buble/src/program/types/ContinueStatement.js +17 -0
- data/vendor/node_modules/buble/src/program/types/ExportDefaultDeclaration.js +10 -0
- data/vendor/node_modules/buble/src/program/types/ExportNamedDeclaration.js +10 -0
- data/vendor/node_modules/buble/src/program/types/ForInStatement.js +76 -0
- data/vendor/node_modules/buble/src/program/types/ForOfStatement.js +89 -0
- data/vendor/node_modules/buble/src/program/types/ForStatement.js +54 -0
- data/vendor/node_modules/buble/src/program/types/FunctionDeclaration.js +25 -0
- data/vendor/node_modules/buble/src/program/types/FunctionExpression.js +74 -0
- data/vendor/node_modules/buble/src/program/types/Identifier.js +54 -0
- data/vendor/node_modules/buble/src/program/types/IfStatement.js +29 -0
- data/vendor/node_modules/buble/src/program/types/ImportDeclaration.js +10 -0
- data/vendor/node_modules/buble/src/program/types/ImportDefaultSpecifier.js +8 -0
- data/vendor/node_modules/buble/src/program/types/ImportSpecifier.js +8 -0
- data/vendor/node_modules/buble/src/program/types/JSXAttribute.js +20 -0
- data/vendor/node_modules/buble/src/program/types/JSXClosingElement.js +27 -0
- data/vendor/node_modules/buble/src/program/types/JSXClosingFragment.js +22 -0
- data/vendor/node_modules/buble/src/program/types/JSXElement.js +57 -0
- data/vendor/node_modules/buble/src/program/types/JSXExpressionContainer.js +10 -0
- data/vendor/node_modules/buble/src/program/types/JSXFragment.js +4 -0
- data/vendor/node_modules/buble/src/program/types/JSXOpeningElement.js +93 -0
- data/vendor/node_modules/buble/src/program/types/JSXOpeningFragment.js +7 -0
- data/vendor/node_modules/buble/src/program/types/JSXSpreadAttribute.js +10 -0
- data/vendor/node_modules/buble/src/program/types/Literal.js +43 -0
- data/vendor/node_modules/buble/src/program/types/MemberExpression.js +13 -0
- data/vendor/node_modules/buble/src/program/types/NewExpression.js +55 -0
- data/vendor/node_modules/buble/src/program/types/ObjectExpression.js +250 -0
- data/vendor/node_modules/buble/src/program/types/Property.js +52 -0
- data/vendor/node_modules/buble/src/program/types/ReturnStatement.js +32 -0
- data/vendor/node_modules/buble/src/program/types/SpreadElement.js +12 -0
- data/vendor/node_modules/buble/src/program/types/Super.js +88 -0
- data/vendor/node_modules/buble/src/program/types/TaggedTemplateExpression.js +63 -0
- data/vendor/node_modules/buble/src/program/types/TemplateElement.js +7 -0
- data/vendor/node_modules/buble/src/program/types/TemplateLiteral.js +80 -0
- data/vendor/node_modules/buble/src/program/types/ThisExpression.js +31 -0
- data/vendor/node_modules/buble/src/program/types/UpdateExpression.js +32 -0
- data/vendor/node_modules/buble/src/program/types/VariableDeclaration.js +101 -0
- data/vendor/node_modules/buble/src/program/types/VariableDeclarator.js +43 -0
- data/vendor/node_modules/buble/src/program/types/index.js +98 -0
- data/vendor/node_modules/buble/src/program/types/shared/LoopStatement.js +105 -0
- data/vendor/node_modules/buble/src/program/types/shared/ModuleDeclaration.js +10 -0
- data/vendor/node_modules/buble/src/program/wrap.js +68 -0
- data/vendor/node_modules/buble/src/support.js +97 -0
- data/vendor/node_modules/buble/src/utils/CompileError.js +30 -0
- data/vendor/node_modules/buble/src/utils/array.js +11 -0
- data/vendor/node_modules/buble/src/utils/checkConst.js +8 -0
- data/vendor/node_modules/buble/src/utils/deindent.js +30 -0
- data/vendor/node_modules/buble/src/utils/destructure.js +377 -0
- data/vendor/node_modules/buble/src/utils/getSnippet.js +30 -0
- data/vendor/node_modules/buble/src/utils/isReference.js +41 -0
- data/vendor/node_modules/buble/src/utils/locate.js +20 -0
- data/vendor/node_modules/buble/src/utils/patterns.js +1 -0
- data/vendor/node_modules/buble/src/utils/removeTrailingComma.js +13 -0
- data/vendor/node_modules/buble/src/utils/reserved.js +6 -0
- data/vendor/node_modules/buble/src/utils/spread.js +70 -0
- data/vendor/node_modules/builtin-modules/builtin-modules.json +39 -0
- data/vendor/node_modules/builtin-modules/index.js +10 -0
- data/vendor/node_modules/builtin-modules/package.json +40 -0
- data/vendor/node_modules/builtin-modules/static.js +2 -0
- data/vendor/node_modules/chalk/index.js +228 -0
- data/vendor/node_modules/chalk/package.json +66 -0
- data/vendor/node_modules/chalk/templates.js +128 -0
- data/vendor/node_modules/chalk/types/index.d.ts +97 -0
- data/vendor/node_modules/color-convert/conversions.js +861 -0
- data/vendor/node_modules/color-convert/index.js +78 -0
- data/vendor/node_modules/color-convert/package.json +46 -0
- data/vendor/node_modules/color-convert/route.js +97 -0
- data/vendor/node_modules/color-name/index.js +152 -0
- data/vendor/node_modules/color-name/package.json +25 -0
- data/vendor/node_modules/color-name/test.js +7 -0
- data/vendor/node_modules/date-time/index.js +33 -0
- data/vendor/node_modules/date-time/package.json +39 -0
- data/vendor/node_modules/escape-string-regexp/index.js +11 -0
- data/vendor/node_modules/escape-string-regexp/package.json +41 -0
- data/vendor/node_modules/estree-walker/dist/estree-walker.es.js +57 -0
- data/vendor/node_modules/estree-walker/dist/estree-walker.umd.js +68 -0
- data/vendor/node_modules/estree-walker/package.json +34 -0
- data/vendor/node_modules/estree-walker/src/estree-walker.js +51 -0
- data/vendor/node_modules/expand-brackets/index.js +163 -0
- data/vendor/node_modules/expand-brackets/package.json +62 -0
- data/vendor/node_modules/expand-range/index.js +43 -0
- data/vendor/node_modules/expand-range/package.json +73 -0
- data/vendor/node_modules/extglob/index.js +178 -0
- data/vendor/node_modules/extglob/package.json +60 -0
- data/vendor/node_modules/filename-regex/index.js +10 -0
- data/vendor/node_modules/filename-regex/package.json +50 -0
- data/vendor/node_modules/fill-range/index.js +408 -0
- data/vendor/node_modules/fill-range/package.json +61 -0
- data/vendor/node_modules/for-in/index.js +16 -0
- data/vendor/node_modules/for-in/package.json +68 -0
- data/vendor/node_modules/for-own/index.js +19 -0
- data/vendor/node_modules/for-own/package.json +70 -0
- data/vendor/node_modules/glob-base/index.js +51 -0
- data/vendor/node_modules/glob-base/package.json +52 -0
- data/vendor/node_modules/glob-parent/index.js +10 -0
- data/vendor/node_modules/glob-parent/package.json +35 -0
- data/vendor/node_modules/glob-parent/test.js +28 -0
- data/vendor/node_modules/has-flag/index.js +8 -0
- data/vendor/node_modules/has-flag/package.json +44 -0
- data/vendor/node_modules/irregular-plurals/irregular-plurals.json +146 -0
- data/vendor/node_modules/irregular-plurals/package.json +39 -0
- data/vendor/node_modules/is-buffer/index.js +21 -0
- data/vendor/node_modules/is-buffer/package.json +51 -0
- data/vendor/node_modules/is-dotfile/index.js +14 -0
- data/vendor/node_modules/is-dotfile/package.json +69 -0
- data/vendor/node_modules/is-equal-shallow/index.js +27 -0
- data/vendor/node_modules/is-equal-shallow/package.json +54 -0
- data/vendor/node_modules/is-extendable/index.js +13 -0
- data/vendor/node_modules/is-extendable/package.json +51 -0
- data/vendor/node_modules/is-extglob/index.js +11 -0
- data/vendor/node_modules/is-extglob/package.json +48 -0
- data/vendor/node_modules/is-glob/index.js +14 -0
- data/vendor/node_modules/is-glob/package.json +60 -0
- data/vendor/node_modules/is-module/index.js +11 -0
- data/vendor/node_modules/is-module/package.json +20 -0
- data/vendor/node_modules/is-number/index.js +19 -0
- data/vendor/node_modules/is-number/package.json +59 -0
- data/vendor/node_modules/is-posix-bracket/index.js +10 -0
- data/vendor/node_modules/is-posix-bracket/package.json +64 -0
- data/vendor/node_modules/is-primitive/index.js +13 -0
- data/vendor/node_modules/is-primitive/package.json +46 -0
- data/vendor/node_modules/is-reference/dist/is-reference.es.js +26 -0
- data/vendor/node_modules/is-reference/dist/is-reference.js +34 -0
- data/vendor/node_modules/is-reference/dist/types/index.d.ts +2 -0
- data/vendor/node_modules/is-reference/package.json +47 -0
- data/vendor/node_modules/isarray/index.js +5 -0
- data/vendor/node_modules/isarray/package.json +45 -0
- data/vendor/node_modules/isarray/test.js +20 -0
- data/vendor/node_modules/isobject/index.js +14 -0
- data/vendor/node_modules/isobject/package.json +67 -0
- data/vendor/node_modules/kind-of/index.js +116 -0
- data/vendor/node_modules/kind-of/package.json +90 -0
- data/vendor/node_modules/locate-character/dist/locate-character.es.js +43 -0
- data/vendor/node_modules/locate-character/dist/locate-character.umd.js +54 -0
- data/vendor/node_modules/locate-character/dist/types/index.d.ts +17 -0
- data/vendor/node_modules/locate-character/package.json +41 -0
- data/vendor/node_modules/magic-string/dist/magic-string.cjs.js +1300 -0
- data/vendor/node_modules/magic-string/dist/magic-string.es.js +1296 -0
- data/vendor/node_modules/magic-string/dist/magic-string.umd.js +1352 -0
- data/vendor/node_modules/magic-string/index.d.ts +83 -0
- data/vendor/node_modules/magic-string/node_modules/vlq/dist/vlq.js +91 -0
- data/vendor/node_modules/magic-string/node_modules/vlq/package.json +27 -0
- data/vendor/node_modules/magic-string/node_modules/vlq/src/vlq.js +78 -0
- data/vendor/node_modules/magic-string/package.json +55 -0
- data/vendor/node_modules/micromatch/index.js +431 -0
- data/vendor/node_modules/micromatch/lib/chars.js +67 -0
- data/vendor/node_modules/micromatch/lib/expand.js +304 -0
- data/vendor/node_modules/micromatch/lib/glob.js +193 -0
- data/vendor/node_modules/micromatch/lib/utils.js +149 -0
- data/vendor/node_modules/micromatch/package.json +114 -0
- data/vendor/node_modules/minimist/index.js +236 -0
- data/vendor/node_modules/minimist/package.json +45 -0
- data/vendor/node_modules/nodent-compiler/compiler.js +171 -0
- data/vendor/node_modules/nodent-compiler/lib/arboriculture.js +2694 -0
- data/vendor/node_modules/nodent-compiler/lib/output.js +934 -0
- data/vendor/node_modules/nodent-compiler/lib/parser.js +291 -0
- data/vendor/node_modules/nodent-compiler/package.json +37 -0
- data/vendor/node_modules/normalize-path/index.js +19 -0
- data/vendor/node_modules/normalize-path/package.json +78 -0
- data/vendor/node_modules/object.omit/index.js +40 -0
- data/vendor/node_modules/object.omit/package.json +67 -0
- data/vendor/node_modules/os-homedir/index.js +24 -0
- data/vendor/node_modules/os-homedir/package.json +41 -0
- data/vendor/node_modules/parse-glob/index.js +156 -0
- data/vendor/node_modules/parse-glob/package.json +62 -0
- data/vendor/node_modules/parse-ms/index.js +16 -0
- data/vendor/node_modules/parse-ms/package.json +34 -0
- data/vendor/node_modules/path-parse/index.js +93 -0
- data/vendor/node_modules/path-parse/index.min.js +1 -0
- data/vendor/node_modules/path-parse/package.json +33 -0
- data/vendor/node_modules/path-parse/test.js +77 -0
- data/vendor/node_modules/path-parse/test.min.js +1 -0
- data/vendor/node_modules/plur/index.js +20 -0
- data/vendor/node_modules/plur/package.json +42 -0
- data/vendor/node_modules/preserve/index.js +54 -0
- data/vendor/node_modules/preserve/package.json +48 -0
- data/vendor/node_modules/preserve/test.js +48 -0
- data/vendor/node_modules/pretty-ms/index.js +48 -0
- data/vendor/node_modules/pretty-ms/package.json +48 -0
- data/vendor/node_modules/randomatic/index.js +82 -0
- data/vendor/node_modules/randomatic/node_modules/is-number/index.js +22 -0
- data/vendor/node_modules/randomatic/node_modules/is-number/node_modules/kind-of/index.js +116 -0
- data/vendor/node_modules/randomatic/node_modules/is-number/node_modules/kind-of/package.json +90 -0
- data/vendor/node_modules/randomatic/node_modules/is-number/package.json +83 -0
- data/vendor/node_modules/randomatic/node_modules/kind-of/index.js +119 -0
- data/vendor/node_modules/randomatic/node_modules/kind-of/package.json +90 -0
- data/vendor/node_modules/randomatic/package.json +78 -0
- data/vendor/node_modules/regex-cache/index.js +68 -0
- data/vendor/node_modules/regex-cache/package.json +64 -0
- data/vendor/node_modules/remove-trailing-separator/index.js +17 -0
- data/vendor/node_modules/remove-trailing-separator/package.json +37 -0
- data/vendor/node_modules/repeat-element/index.js +18 -0
- data/vendor/node_modules/repeat-element/package.json +44 -0
- data/vendor/node_modules/repeat-string/index.js +70 -0
- data/vendor/node_modules/repeat-string/package.json +77 -0
- data/vendor/node_modules/require-relative/index.js +33 -0
- data/vendor/node_modules/require-relative/package.json +22 -0
- data/vendor/node_modules/resolve/index.js +8 -0
- data/vendor/node_modules/resolve/lib/async.js +203 -0
- data/vendor/node_modules/resolve/lib/caller.js +8 -0
- data/vendor/node_modules/resolve/lib/core.js +53 -0
- data/vendor/node_modules/resolve/lib/core.json +69 -0
- data/vendor/node_modules/resolve/lib/node-modules-paths.js +45 -0
- data/vendor/node_modules/resolve/lib/sync.js +93 -0
- data/vendor/node_modules/resolve/package.json +40 -0
- data/vendor/node_modules/rollup-plugin-commonjs/dist/rollup-plugin-commonjs.cjs.js +804 -0
- data/vendor/node_modules/rollup-plugin-commonjs/dist/rollup-plugin-commonjs.es.js +800 -0
- data/vendor/node_modules/rollup-plugin-commonjs/package.json +52 -0
- data/vendor/node_modules/rollup-plugin-commonjs/src/ast-utils.js +104 -0
- data/vendor/node_modules/rollup-plugin-commonjs/src/defaultResolver.js +39 -0
- data/vendor/node_modules/rollup-plugin-commonjs/src/helpers.js +19 -0
- data/vendor/node_modules/rollup-plugin-commonjs/src/index.js +198 -0
- data/vendor/node_modules/rollup-plugin-commonjs/src/transform.js +431 -0
- data/vendor/node_modules/rollup-plugin-commonjs/src/utils.js +13 -0
- data/vendor/node_modules/rollup-plugin-node-resolve/dist/rollup-plugin-node-resolve.cjs.js +218 -0
- data/vendor/node_modules/rollup-plugin-node-resolve/dist/rollup-plugin-node-resolve.es.js +214 -0
- data/vendor/node_modules/rollup-plugin-node-resolve/package.json +51 -0
- data/vendor/node_modules/rollup-plugin-node-resolve/src/empty.js +1 -0
- data/vendor/node_modules/rollup-plugin-node-resolve/src/index.js +205 -0
- data/vendor/node_modules/rollup-pluginutils/dist/pluginutils.cjs.js +223 -0
- data/vendor/node_modules/rollup-pluginutils/dist/pluginutils.es.js +214 -0
- data/vendor/node_modules/rollup-pluginutils/dist/pluginutils.es6.js +217 -0
- data/vendor/node_modules/rollup-pluginutils/node_modules/estree-walker/dist/estree-walker.es.js +55 -0
- data/vendor/node_modules/rollup-pluginutils/node_modules/estree-walker/dist/estree-walker.es6.js +59 -0
- data/vendor/node_modules/rollup-pluginutils/node_modules/estree-walker/dist/estree-walker.umd.js +65 -0
- data/vendor/node_modules/rollup-pluginutils/node_modules/estree-walker/package.json +33 -0
- data/vendor/node_modules/rollup-pluginutils/node_modules/estree-walker/src/estree-walker.js +49 -0
- data/vendor/node_modules/rollup-pluginutils/package.json +40 -0
- data/vendor/node_modules/rollup-pluginutils/src/addExtension.js +6 -0
- data/vendor/node_modules/rollup-pluginutils/src/attachScopes.js +147 -0
- data/vendor/node_modules/rollup-pluginutils/src/createFilter.js +33 -0
- data/vendor/node_modules/rollup-pluginutils/src/index.js +4 -0
- data/vendor/node_modules/rollup-pluginutils/src/makeLegalIdentifier.js +15 -0
- data/vendor/node_modules/rollup-pluginutils/src/utils/ensureArray.js +5 -0
- data/vendor/node_modules/rollup/bin/rollup +4085 -0
- data/vendor/node_modules/rollup/dist/rollup.browser.js +19829 -0
- data/vendor/node_modules/rollup/dist/rollup.es.js +23586 -0
- data/vendor/node_modules/rollup/dist/rollup.js +23597 -0
- data/vendor/node_modules/rollup/dist/typings/Chunk.d.ts +85 -0
- data/vendor/node_modules/rollup/dist/typings/ExternalModule.d.ts +30 -0
- data/vendor/node_modules/rollup/dist/typings/Graph.d.ts +47 -0
- data/vendor/node_modules/rollup/dist/typings/Module.d.ts +130 -0
- data/vendor/node_modules/rollup/dist/typings/ast/CallOptions.d.ts +20 -0
- data/vendor/node_modules/rollup/dist/typings/ast/Entity.d.ts +16 -0
- data/vendor/node_modules/rollup/dist/typings/ast/ExecutionPathOptions.d.ts +57 -0
- data/vendor/node_modules/rollup/dist/typings/ast/clone.d.ts +1 -0
- data/vendor/node_modules/rollup/dist/typings/ast/enhance.d.ts +3 -0
- data/vendor/node_modules/rollup/dist/typings/ast/keys.d.ts +4 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/ArrayExpression.d.ts +14 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/ArrayPattern.d.ts +14 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/ArrowFunctionExpression.d.ts +25 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/AssignmentExpression.d.ts +13 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/AssignmentPattern.d.ts +16 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/AssignmentProperty.d.ts +10 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/AwaitExpression.d.ts +8 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/BinaryExpression.d.ts +13 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/BlockStatement.d.ts +19 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/BreakStatement.d.ts +9 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/CallExpression.d.ts +22 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/CatchClause.d.ts +14 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/ClassBody.d.ts +13 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/ClassDeclaration.d.ts +14 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/ClassExpression.d.ts +10 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/ConditionalExpression.d.ts +28 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/DoWhileStatement.d.ts +9 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/EmptyStatement.d.ts +8 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/ExportAllDeclaration.d.ts +12 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/ExportDefaultDeclaration.d.ts +21 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/ExportNamedDeclaration.d.ts +21 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/ExportSpecifier.d.ts +8 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/ExpressionStatement.d.ts +10 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/ForInStatement.d.ts +20 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/ForOfStatement.d.ts +21 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/ForStatement.d.ts +19 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/FunctionDeclaration.d.ts +9 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/FunctionExpression.d.ts +6 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/Identifier.d.ts +29 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/IfStatement.d.ts +17 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/Import.d.ts +14 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/ImportDeclaration.d.ts +17 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/ImportDefaultSpecifier.d.ts +7 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/ImportNamespaceSpecifier.d.ts +7 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/ImportSpecifier.d.ts +8 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/LabeledStatement.d.ts +10 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/Literal.d.ts +22 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/LogicalExpression.d.ts +23 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/MemberExpression.d.ts +34 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/MethodDefinition.d.ts +16 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/NewExpression.d.ts +14 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/NodeType.d.ts +64 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/ObjectExpression.d.ts +22 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/ObjectPattern.d.ts +15 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/Program.d.ts +9 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/Property.d.ts +30 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/RestElement.d.ts +14 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/ReturnStatement.d.ts +9 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/SequenceExpression.d.ts +13 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/SpreadElement.d.ts +6 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/SwitchCase.d.ts +11 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/SwitchStatement.d.ts +12 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/TaggedTemplateExpression.d.ts +13 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/TemplateElement.d.ts +12 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/TemplateLiteral.d.ts +12 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/ThisExpression.d.ts +17 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/ThrowStatement.d.ts +8 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/UnaryExpression.d.ts +16 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/UnknownNode.d.ts +5 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/UpdateExpression.d.ts +13 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/VariableDeclaration.d.ts +21 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/VariableDeclarator.d.ts +13 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/WhileStatement.d.ts +9 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/YieldExpression.d.ts +9 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/index.d.ts +6 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/shared/ClassNode.d.ts +17 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/shared/Expression.d.ts +21 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/shared/FunctionNode.d.ts +25 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/shared/Node.d.ts +133 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/shared/Pattern.d.ts +4 -0
- data/vendor/node_modules/rollup/dist/typings/ast/nodes/shared/pureFunctions.d.ts +4 -0
- data/vendor/node_modules/rollup/dist/typings/ast/scopes/BlockScope.d.ts +9 -0
- data/vendor/node_modules/rollup/dist/typings/ast/scopes/CatchScope.d.ts +10 -0
- data/vendor/node_modules/rollup/dist/typings/ast/scopes/FunctionScope.d.ts +20 -0
- data/vendor/node_modules/rollup/dist/typings/ast/scopes/GlobalScope.d.ts +7 -0
- data/vendor/node_modules/rollup/dist/typings/ast/scopes/ModuleScope.d.ts +11 -0
- data/vendor/node_modules/rollup/dist/typings/ast/scopes/ParameterScope.d.ts +16 -0
- data/vendor/node_modules/rollup/dist/typings/ast/scopes/ReturnValueScope.d.ts +11 -0
- data/vendor/node_modules/rollup/dist/typings/ast/scopes/Scope.d.ts +42 -0
- data/vendor/node_modules/rollup/dist/typings/ast/utils/extractNames.d.ts +2 -0
- data/vendor/node_modules/rollup/dist/typings/ast/values.d.ts +31 -0
- data/vendor/node_modules/rollup/dist/typings/ast/variables/ArgumentsVariable.d.ts +15 -0
- data/vendor/node_modules/rollup/dist/typings/ast/variables/ExportDefaultVariable.d.ts +16 -0
- data/vendor/node_modules/rollup/dist/typings/ast/variables/ExternalVariable.d.ts +12 -0
- data/vendor/node_modules/rollup/dist/typings/ast/variables/GlobalVariable.d.ts +11 -0
- data/vendor/node_modules/rollup/dist/typings/ast/variables/LocalVariable.d.ts +21 -0
- data/vendor/node_modules/rollup/dist/typings/ast/variables/NamespaceVariable.d.ts +20 -0
- data/vendor/node_modules/rollup/dist/typings/ast/variables/ParameterVariable.d.ts +5 -0
- data/vendor/node_modules/rollup/dist/typings/ast/variables/ReplaceableInitializationVariable.d.ts +14 -0
- data/vendor/node_modules/rollup/dist/typings/ast/variables/ThisVariable.d.ts +4 -0
- data/vendor/node_modules/rollup/dist/typings/ast/variables/Variable.d.ts +43 -0
- data/vendor/node_modules/rollup/dist/typings/ast/variables/VariableReassignmentTracker.d.ts +11 -0
- data/vendor/node_modules/rollup/dist/typings/finalisers/amd.d.ts +11 -0
- data/vendor/node_modules/rollup/dist/typings/finalisers/cjs.d.ts +10 -0
- data/vendor/node_modules/rollup/dist/typings/finalisers/es.d.ts +9 -0
- data/vendor/node_modules/rollup/dist/typings/finalisers/iife.d.ts +10 -0
- data/vendor/node_modules/rollup/dist/typings/finalisers/index.d.ts +15 -0
- data/vendor/node_modules/rollup/dist/typings/finalisers/shared/esModuleExport.d.ts +2 -0
- data/vendor/node_modules/rollup/dist/typings/finalisers/shared/getExportBlock.d.ts +2 -0
- data/vendor/node_modules/rollup/dist/typings/finalisers/shared/getGlobalNameMaker.d.ts +4 -0
- data/vendor/node_modules/rollup/dist/typings/finalisers/shared/getInteropBlock.d.ts +3 -0
- data/vendor/node_modules/rollup/dist/typings/finalisers/shared/sanitize.d.ts +2 -0
- data/vendor/node_modules/rollup/dist/typings/finalisers/shared/setupNamespace.d.ts +2 -0
- data/vendor/node_modules/rollup/dist/typings/finalisers/shared/trimEmptyImports.d.ts +2 -0
- data/vendor/node_modules/rollup/dist/typings/finalisers/shared/warnOnBuiltins.d.ts +2 -0
- data/vendor/node_modules/rollup/dist/typings/finalisers/system.d.ts +8 -0
- data/vendor/node_modules/rollup/dist/typings/finalisers/umd.d.ts +10 -0
- data/vendor/node_modules/rollup/dist/typings/node-entry.d.ts +6 -0
- data/vendor/node_modules/rollup/dist/typings/rollup/index.d.ts +167 -0
- data/vendor/node_modules/rollup/dist/typings/utils/callIfFunction.d.ts +1 -0
- data/vendor/node_modules/rollup/dist/typings/utils/collapseSourcemaps.d.ts +5 -0
- data/vendor/node_modules/rollup/dist/typings/utils/commondir.d.ts +1 -0
- data/vendor/node_modules/rollup/dist/typings/utils/defaults.d.ts +6 -0
- data/vendor/node_modules/rollup/dist/typings/utils/deprecateOptions.d.ts +6 -0
- data/vendor/node_modules/rollup/dist/typings/utils/ensureArray.d.ts +2 -0
- data/vendor/node_modules/rollup/dist/typings/utils/entryHashing.d.ts +3 -0
- data/vendor/node_modules/rollup/dist/typings/utils/error.d.ts +18 -0
- data/vendor/node_modules/rollup/dist/typings/utils/first-sync.d.ts +1 -0
- data/vendor/node_modules/rollup/dist/typings/utils/first.d.ts +1 -0
- data/vendor/node_modules/rollup/dist/typings/utils/flushTime.d.ts +5 -0
- data/vendor/node_modules/rollup/dist/typings/utils/fs.d.ts +3 -0
- data/vendor/node_modules/rollup/dist/typings/utils/getCodeFrame.d.ts +1 -0
- data/vendor/node_modules/rollup/dist/typings/utils/getExportMode.d.ts +3 -0
- data/vendor/node_modules/rollup/dist/typings/utils/getIndentString.d.ts +4 -0
- data/vendor/node_modules/rollup/dist/typings/utils/identifierHelpers.d.ts +3 -0
- data/vendor/node_modules/rollup/dist/typings/utils/mergeOptions.d.ts +19 -0
- data/vendor/node_modules/rollup/dist/typings/utils/object.d.ts +7 -0
- data/vendor/node_modules/rollup/dist/typings/utils/path.d.ts +6 -0
- data/vendor/node_modules/rollup/dist/typings/utils/promise.d.ts +2 -0
- data/vendor/node_modules/rollup/dist/typings/utils/relativeId.d.ts +1 -0
- data/vendor/node_modules/rollup/dist/typings/utils/renderHelpers.d.ts +26 -0
- data/vendor/node_modules/rollup/dist/typings/utils/sourceMappingURL.d.ts +3 -0
- data/vendor/node_modules/rollup/dist/typings/utils/timers.d.ts +7 -0
- data/vendor/node_modules/rollup/dist/typings/utils/transform.d.ts +25 -0
- data/vendor/node_modules/rollup/dist/typings/utils/transformBundle.d.ts +3 -0
- data/vendor/node_modules/rollup/dist/typings/watch/chokidar.d.ts +3 -0
- data/vendor/node_modules/rollup/dist/typings/watch/fileWatchers.d.ts +14 -0
- data/vendor/node_modules/rollup/dist/typings/watch/index.d.ts +47 -0
- data/vendor/node_modules/rollup/package.json +122 -0
- data/vendor/node_modules/rollup/typings/package.json.d.ts +3 -0
- data/vendor/node_modules/signal-exit/index.js +157 -0
- data/vendor/node_modules/signal-exit/package.json +38 -0
- data/vendor/node_modules/signal-exit/signals.js +53 -0
- data/vendor/node_modules/source-map/dist/source-map.debug.js +3091 -0
- data/vendor/node_modules/source-map/dist/source-map.js +3090 -0
- data/vendor/node_modules/source-map/dist/source-map.min.js +2 -0
- data/vendor/node_modules/source-map/lib/array-set.js +121 -0
- data/vendor/node_modules/source-map/lib/base64-vlq.js +140 -0
- data/vendor/node_modules/source-map/lib/base64.js +67 -0
- data/vendor/node_modules/source-map/lib/binary-search.js +111 -0
- data/vendor/node_modules/source-map/lib/mapping-list.js +79 -0
- data/vendor/node_modules/source-map/lib/quick-sort.js +114 -0
- data/vendor/node_modules/source-map/lib/source-map-consumer.js +1082 -0
- data/vendor/node_modules/source-map/lib/source-map-generator.js +416 -0
- data/vendor/node_modules/source-map/lib/source-node.js +413 -0
- data/vendor/node_modules/source-map/lib/util.js +417 -0
- data/vendor/node_modules/source-map/package.json +72 -0
- data/vendor/node_modules/source-map/source-map.js +8 -0
- data/vendor/node_modules/sourcemap-codec/dist/sourcemap-codec.es.js +129 -0
- data/vendor/node_modules/sourcemap-codec/dist/sourcemap-codec.umd.js +140 -0
- data/vendor/node_modules/sourcemap-codec/dist/types/sourcemap-codec.d.ts +5 -0
- data/vendor/node_modules/sourcemap-codec/package.json +52 -0
- data/vendor/node_modules/supports-color/browser.js +5 -0
- data/vendor/node_modules/supports-color/index.js +135 -0
- data/vendor/node_modules/supports-color/package.json +53 -0
- data/vendor/node_modules/time-zone/index.js +10 -0
- data/vendor/node_modules/time-zone/package.json +35 -0
- data/vendor/node_modules/vlq/dist/types/vlq.d.ts +2 -0
- data/vendor/node_modules/vlq/dist/vlq.es.js +64 -0
- data/vendor/node_modules/vlq/dist/vlq.js +75 -0
- data/vendor/node_modules/vlq/package.json +30 -0
- data/vendor/package.json +15 -0
- data/vendor/yarn.lock +453 -0
- metadata +641 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
{
|
2
|
+
"name": "rollup-plugin-commonjs",
|
3
|
+
"version": "9.1.0",
|
4
|
+
"description": "Convert CommonJS modules to ES2015",
|
5
|
+
"main": "dist/rollup-plugin-commonjs.cjs.js",
|
6
|
+
"module": "dist/rollup-plugin-commonjs.es.js",
|
7
|
+
"jsnext:main": "dist/rollup-plugin-commonjs.es.js",
|
8
|
+
"scripts": {
|
9
|
+
"test": "npm run test:only",
|
10
|
+
"test:only": "mocha",
|
11
|
+
"pretest": "npm run build",
|
12
|
+
"build": "shx rm -rf dist/* && rollup -c",
|
13
|
+
"dev": "rollup -c -w",
|
14
|
+
"lint": "eslint src/*.js test/*.js",
|
15
|
+
"prepublishOnly": "npm run lint && npm run test:only",
|
16
|
+
"prepare": "npm run build"
|
17
|
+
},
|
18
|
+
"files": [
|
19
|
+
"src",
|
20
|
+
"dist",
|
21
|
+
"README.md"
|
22
|
+
],
|
23
|
+
"peerDependencies": {
|
24
|
+
"rollup": ">=0.56.0"
|
25
|
+
},
|
26
|
+
"dependencies": {
|
27
|
+
"estree-walker": "^0.5.1",
|
28
|
+
"magic-string": "^0.22.4",
|
29
|
+
"resolve": "^1.5.0",
|
30
|
+
"rollup-pluginutils": "^2.0.1"
|
31
|
+
},
|
32
|
+
"devDependencies": {
|
33
|
+
"acorn": "^5.5.0",
|
34
|
+
"eslint": "^4.18.2",
|
35
|
+
"locate-character": "^2.0.5",
|
36
|
+
"mocha": "^5.0.1",
|
37
|
+
"require-relative": "^0.8.7",
|
38
|
+
"rollup": "^0.56.4",
|
39
|
+
"rollup-plugin-buble": "^0.19.2",
|
40
|
+
"rollup-plugin-node-resolve": "^3.0.3",
|
41
|
+
"shx": "^0.2.2",
|
42
|
+
"source-map": "^0.6.1",
|
43
|
+
"source-map-support": "^0.5.3"
|
44
|
+
},
|
45
|
+
"repository": "rollup/rollup-plugin-commonjs",
|
46
|
+
"author": "Rich Harris",
|
47
|
+
"license": "MIT",
|
48
|
+
"bugs": {
|
49
|
+
"url": "https://github.com/rollup/rollup-plugin-commonjs/issues"
|
50
|
+
},
|
51
|
+
"homepage": "https://github.com/rollup/rollup-plugin-commonjs"
|
52
|
+
}
|
@@ -0,0 +1,104 @@
|
|
1
|
+
export function isReference ( node, parent ) {
|
2
|
+
if ( parent.type === 'MemberExpression' ) return parent.computed || node === parent.object;
|
3
|
+
|
4
|
+
// disregard the `bar` in { bar: foo }
|
5
|
+
if ( parent.type === 'Property' && node !== parent.value ) return false;
|
6
|
+
|
7
|
+
// disregard the `bar` in `class Foo { bar () {...} }`
|
8
|
+
if ( parent.type === 'MethodDefinition' ) return false;
|
9
|
+
|
10
|
+
// disregard the `bar` in `export { foo as bar }`
|
11
|
+
if ( parent.type === 'ExportSpecifier' && node !== parent.local ) return false;
|
12
|
+
|
13
|
+
return true;
|
14
|
+
}
|
15
|
+
|
16
|
+
export function flatten ( node ) {
|
17
|
+
const parts = [];
|
18
|
+
|
19
|
+
while ( node.type === 'MemberExpression' ) {
|
20
|
+
if ( node.computed ) return null;
|
21
|
+
|
22
|
+
parts.unshift( node.property.name );
|
23
|
+
node = node.object;
|
24
|
+
}
|
25
|
+
|
26
|
+
if ( node.type !== 'Identifier' ) return null;
|
27
|
+
|
28
|
+
const name = node.name;
|
29
|
+
parts.unshift( name );
|
30
|
+
|
31
|
+
return { name, keypath: parts.join( '.' ) };
|
32
|
+
}
|
33
|
+
|
34
|
+
export function extractNames ( node ) {
|
35
|
+
const names = [];
|
36
|
+
extractors[ node.type ]( names, node );
|
37
|
+
return names;
|
38
|
+
}
|
39
|
+
|
40
|
+
const extractors = {
|
41
|
+
Identifier ( names, node ) {
|
42
|
+
names.push( node.name );
|
43
|
+
},
|
44
|
+
|
45
|
+
ObjectPattern ( names, node ) {
|
46
|
+
node.properties.forEach( prop => {
|
47
|
+
extractors[ prop.value.type ]( names, prop.value );
|
48
|
+
});
|
49
|
+
},
|
50
|
+
|
51
|
+
ArrayPattern ( names, node ) {
|
52
|
+
node.elements.forEach( element => {
|
53
|
+
if ( element ) extractors[ element.type ]( names, element );
|
54
|
+
});
|
55
|
+
},
|
56
|
+
|
57
|
+
RestElement ( names, node ) {
|
58
|
+
extractors[ node.argument.type ]( names, node.argument );
|
59
|
+
},
|
60
|
+
|
61
|
+
AssignmentPattern ( names, node ) {
|
62
|
+
extractors[ node.left.type ]( names, node.left );
|
63
|
+
}
|
64
|
+
};
|
65
|
+
|
66
|
+
|
67
|
+
export function isTruthy ( node ) {
|
68
|
+
if ( node.type === 'Literal' ) return !!node.value;
|
69
|
+
if ( node.type === 'ParenthesizedExpression' ) return isTruthy( node.expression );
|
70
|
+
if ( node.operator in operators ) return operators[ node.operator ]( node );
|
71
|
+
}
|
72
|
+
|
73
|
+
export function isFalsy ( node ) {
|
74
|
+
return not( isTruthy( node ) );
|
75
|
+
}
|
76
|
+
|
77
|
+
function not ( value ) {
|
78
|
+
return value === undefined ? value : !value;
|
79
|
+
}
|
80
|
+
|
81
|
+
function equals ( a, b, strict ) {
|
82
|
+
if ( a.type !== b.type ) return undefined;
|
83
|
+
if ( a.type === 'Literal' ) return strict ? a.value === b.value : a.value == b.value;
|
84
|
+
}
|
85
|
+
|
86
|
+
const operators = {
|
87
|
+
'==': x => {
|
88
|
+
return equals( x.left, x.right, false );
|
89
|
+
},
|
90
|
+
|
91
|
+
'!=': x => not( operators['==']( x ) ),
|
92
|
+
|
93
|
+
'===': x => {
|
94
|
+
return equals( x.left, x.right, true );
|
95
|
+
},
|
96
|
+
|
97
|
+
'!==': x => not( operators['===']( x ) ),
|
98
|
+
|
99
|
+
'!': x => isFalsy( x.argument ),
|
100
|
+
|
101
|
+
'&&': x => isTruthy( x.left ) && isTruthy( x.right ),
|
102
|
+
|
103
|
+
'||': x => isTruthy( x.left ) || isTruthy( x.right )
|
104
|
+
};
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import * as fs from 'fs';
|
2
|
+
import { dirname, resolve } from 'path';
|
3
|
+
|
4
|
+
function isFile ( file ) {
|
5
|
+
try {
|
6
|
+
const stats = fs.statSync( file );
|
7
|
+
return stats.isFile();
|
8
|
+
} catch ( err ) {
|
9
|
+
return false;
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
function addJsExtensionIfNecessary ( file ) {
|
14
|
+
if ( isFile( file ) ) return file;
|
15
|
+
|
16
|
+
file += '.js';
|
17
|
+
if ( isFile( file ) ) return file;
|
18
|
+
|
19
|
+
return null;
|
20
|
+
}
|
21
|
+
|
22
|
+
const absolutePath = /^(?:\/|(?:[A-Za-z]:)?[\\|/])/;
|
23
|
+
|
24
|
+
function isAbsolute ( path ) {
|
25
|
+
return absolutePath.test( path );
|
26
|
+
}
|
27
|
+
|
28
|
+
export default function defaultResolver ( importee, importer ) {
|
29
|
+
// absolute paths are left untouched
|
30
|
+
if ( isAbsolute( importee ) ) return addJsExtensionIfNecessary( resolve( importee ) );
|
31
|
+
|
32
|
+
// if this is the entry point, resolve against cwd
|
33
|
+
if ( importer === undefined ) return addJsExtensionIfNecessary( resolve( process.cwd(), importee ) );
|
34
|
+
|
35
|
+
// external modules are skipped at this stage
|
36
|
+
if ( importee[0] !== '.' ) return null;
|
37
|
+
|
38
|
+
return addJsExtensionIfNecessary( resolve( dirname( importer ), importee ) );
|
39
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
export const HELPERS_ID = '\0commonjsHelpers';
|
2
|
+
|
3
|
+
export const HELPERS = `
|
4
|
+
export var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
5
|
+
|
6
|
+
export function commonjsRequire () {
|
7
|
+
throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
|
8
|
+
}
|
9
|
+
|
10
|
+
export function unwrapExports (x) {
|
11
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
12
|
+
}
|
13
|
+
|
14
|
+
export function createCommonjsModule(fn, module) {
|
15
|
+
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
16
|
+
}`;
|
17
|
+
|
18
|
+
export const PREFIX = '\0commonjs-proxy:';
|
19
|
+
export const EXTERNAL = '\0commonjs-external:';
|
@@ -0,0 +1,198 @@
|
|
1
|
+
import { statSync } from 'fs';
|
2
|
+
import { dirname, extname, resolve, sep } from 'path';
|
3
|
+
import { sync as nodeResolveSync } from 'resolve';
|
4
|
+
import { createFilter } from 'rollup-pluginutils';
|
5
|
+
import { EXTERNAL, PREFIX, HELPERS_ID, HELPERS } from './helpers.js';
|
6
|
+
import defaultResolver from './defaultResolver.js';
|
7
|
+
import { checkFirstpass, checkEsModule, transformCommonjs } from './transform.js';
|
8
|
+
import { getName } from './utils.js';
|
9
|
+
|
10
|
+
function getCandidatesForExtension ( resolved, extension ) {
|
11
|
+
return [
|
12
|
+
resolved + extension,
|
13
|
+
resolved + `${sep}index${extension}`
|
14
|
+
];
|
15
|
+
}
|
16
|
+
|
17
|
+
function getCandidates ( resolved, extensions ) {
|
18
|
+
return extensions.reduce(
|
19
|
+
( paths, extension ) => paths.concat( getCandidatesForExtension ( resolved, extension ) ),
|
20
|
+
[resolved]
|
21
|
+
);
|
22
|
+
}
|
23
|
+
|
24
|
+
// Return the first non-falsy result from an array of
|
25
|
+
// maybe-sync, maybe-promise-returning functions
|
26
|
+
function first ( candidates ) {
|
27
|
+
return function ( ...args ) {
|
28
|
+
return candidates.reduce( ( promise, candidate ) => {
|
29
|
+
return promise.then( result => result != null ?
|
30
|
+
result :
|
31
|
+
Promise.resolve( candidate( ...args ) ) );
|
32
|
+
}, Promise.resolve() );
|
33
|
+
};
|
34
|
+
}
|
35
|
+
|
36
|
+
function startsWith ( str, prefix ) {
|
37
|
+
return str.slice( 0, prefix.length ) === prefix;
|
38
|
+
}
|
39
|
+
|
40
|
+
|
41
|
+
export default function commonjs ( options = {} ) {
|
42
|
+
const extensions = options.extensions || ['.js'];
|
43
|
+
const filter = createFilter( options.include, options.exclude );
|
44
|
+
const ignoreGlobal = options.ignoreGlobal;
|
45
|
+
|
46
|
+
const customNamedExports = {};
|
47
|
+
if ( options.namedExports ) {
|
48
|
+
Object.keys( options.namedExports ).forEach( id => {
|
49
|
+
let resolvedId;
|
50
|
+
|
51
|
+
try {
|
52
|
+
resolvedId = nodeResolveSync( id, { basedir: process.cwd() });
|
53
|
+
} catch ( err ) {
|
54
|
+
resolvedId = resolve( id );
|
55
|
+
}
|
56
|
+
|
57
|
+
customNamedExports[ resolvedId ] = options.namedExports[ id ];
|
58
|
+
});
|
59
|
+
}
|
60
|
+
|
61
|
+
const esModulesWithoutDefaultExport = [];
|
62
|
+
|
63
|
+
const allowDynamicRequire = !!options.ignore; // TODO maybe this should be configurable?
|
64
|
+
|
65
|
+
const ignoreRequire = typeof options.ignore === 'function' ?
|
66
|
+
options.ignore :
|
67
|
+
Array.isArray( options.ignore ) ? id => ~options.ignore.indexOf( id ) :
|
68
|
+
() => false;
|
69
|
+
|
70
|
+
let entryModuleIdsPromise = null;
|
71
|
+
|
72
|
+
function resolveId ( importee, importer ) {
|
73
|
+
if ( importee === HELPERS_ID ) return importee;
|
74
|
+
|
75
|
+
if ( importer && startsWith( importer, PREFIX ) ) importer = importer.slice( PREFIX.length );
|
76
|
+
|
77
|
+
const isProxyModule = startsWith( importee, PREFIX );
|
78
|
+
if ( isProxyModule ) importee = importee.slice( PREFIX.length );
|
79
|
+
|
80
|
+
return resolveUsingOtherResolvers( importee, importer ).then( resolved => {
|
81
|
+
if ( resolved ) return isProxyModule ? PREFIX + resolved : resolved;
|
82
|
+
|
83
|
+
resolved = defaultResolver( importee, importer );
|
84
|
+
|
85
|
+
if ( isProxyModule ) {
|
86
|
+
if ( resolved ) return PREFIX + resolved;
|
87
|
+
return EXTERNAL + importee; // external
|
88
|
+
}
|
89
|
+
|
90
|
+
return resolved;
|
91
|
+
});
|
92
|
+
}
|
93
|
+
|
94
|
+
const sourceMap = options.sourceMap !== false;
|
95
|
+
|
96
|
+
const commonjsModules = new Map();
|
97
|
+
let resolveUsingOtherResolvers;
|
98
|
+
|
99
|
+
return {
|
100
|
+
name: 'commonjs',
|
101
|
+
|
102
|
+
options ( options ) {
|
103
|
+
const resolvers = ( options.plugins || [] )
|
104
|
+
.map( plugin => {
|
105
|
+
if ( plugin.resolveId === resolveId ) {
|
106
|
+
// substitute CommonJS resolution logic
|
107
|
+
return ( importee, importer ) => {
|
108
|
+
if ( importee[0] !== '.' || !importer ) return; // not our problem
|
109
|
+
|
110
|
+
const resolved = resolve( dirname( importer ), importee );
|
111
|
+
const candidates = getCandidates( resolved, extensions );
|
112
|
+
|
113
|
+
for ( let i = 0; i < candidates.length; i += 1 ) {
|
114
|
+
try {
|
115
|
+
const stats = statSync( candidates[i] );
|
116
|
+
if ( stats.isFile() ) return candidates[i];
|
117
|
+
} catch ( err ) { /* noop */ }
|
118
|
+
}
|
119
|
+
};
|
120
|
+
}
|
121
|
+
|
122
|
+
return plugin.resolveId;
|
123
|
+
})
|
124
|
+
.filter( Boolean );
|
125
|
+
|
126
|
+
const isExternal = id => options.external ?
|
127
|
+
Array.isArray( options.external ) ? ~options.external.indexOf( id ) :
|
128
|
+
options.external(id) :
|
129
|
+
false;
|
130
|
+
|
131
|
+
resolvers.unshift( id => isExternal( id ) ? false : null );
|
132
|
+
|
133
|
+
resolveUsingOtherResolvers = first( resolvers );
|
134
|
+
|
135
|
+
const entryModules = [].concat( options.input || options.entry );
|
136
|
+
entryModuleIdsPromise = Promise.all(
|
137
|
+
entryModules.map( entry => resolveId( entry ))
|
138
|
+
);
|
139
|
+
},
|
140
|
+
|
141
|
+
resolveId,
|
142
|
+
|
143
|
+
load ( id ) {
|
144
|
+
if ( id === HELPERS_ID ) return HELPERS;
|
145
|
+
|
146
|
+
// generate proxy modules
|
147
|
+
if ( startsWith( id, EXTERNAL ) ) {
|
148
|
+
const actualId = id.slice( EXTERNAL.length );
|
149
|
+
const name = getName( actualId );
|
150
|
+
|
151
|
+
return `import ${name} from ${JSON.stringify( actualId )}; export default ${name};`;
|
152
|
+
}
|
153
|
+
|
154
|
+
if ( startsWith( id, PREFIX ) ) {
|
155
|
+
const actualId = id.slice( PREFIX.length );
|
156
|
+
const name = getName( actualId );
|
157
|
+
|
158
|
+
if (commonjsModules.has( actualId ))
|
159
|
+
return `import { __moduleExports } from ${JSON.stringify( actualId )}; export default __moduleExports;`;
|
160
|
+
else if (esModulesWithoutDefaultExport.indexOf(actualId) !== -1)
|
161
|
+
return `import * as ${name} from ${JSON.stringify( actualId )}; export default ${name};`;
|
162
|
+
else
|
163
|
+
return `import * as ${name} from ${JSON.stringify( actualId )}; export default ( ${name} && ${name}['default'] ) || ${name};`;
|
164
|
+
}
|
165
|
+
},
|
166
|
+
|
167
|
+
transform ( code, id ) {
|
168
|
+
if ( !filter( id ) ) return null;
|
169
|
+
if ( extensions.indexOf( extname( id ) ) === -1 ) return null;
|
170
|
+
|
171
|
+
return entryModuleIdsPromise.then( (entryModuleIds) => {
|
172
|
+
const {isEsModule, hasDefaultExport, ast} = checkEsModule( this.parse, code, id );
|
173
|
+
if ( isEsModule ) {
|
174
|
+
if ( !hasDefaultExport )
|
175
|
+
esModulesWithoutDefaultExport.push( id );
|
176
|
+
return;
|
177
|
+
}
|
178
|
+
|
179
|
+
// it is not an ES module but not a commonjs module, too.
|
180
|
+
if ( !checkFirstpass( code, ignoreGlobal ) ) {
|
181
|
+
esModulesWithoutDefaultExport.push( id );
|
182
|
+
return;
|
183
|
+
}
|
184
|
+
|
185
|
+
const transformed = transformCommonjs( this.parse, code, id, entryModuleIds.indexOf(id) !== -1, ignoreGlobal, ignoreRequire, customNamedExports[ id ], sourceMap, allowDynamicRequire, ast );
|
186
|
+
if ( !transformed ) {
|
187
|
+
esModulesWithoutDefaultExport.push( id );
|
188
|
+
return;
|
189
|
+
}
|
190
|
+
|
191
|
+
commonjsModules.set( id, true );
|
192
|
+
return transformed;
|
193
|
+
}).catch(err => {
|
194
|
+
this.error(err, err.loc);
|
195
|
+
});
|
196
|
+
}
|
197
|
+
};
|
198
|
+
}
|
@@ -0,0 +1,431 @@
|
|
1
|
+
import { walk } from 'estree-walker';
|
2
|
+
import MagicString from 'magic-string';
|
3
|
+
import { attachScopes, makeLegalIdentifier } from 'rollup-pluginutils';
|
4
|
+
import { extractNames, flatten, isReference, isTruthy, isFalsy } from './ast-utils.js';
|
5
|
+
import { PREFIX, HELPERS_ID } from './helpers.js';
|
6
|
+
import { getName } from './utils.js';
|
7
|
+
|
8
|
+
const reserved = 'abstract arguments boolean break byte case catch char class const continue debugger default delete do double else enum eval export extends false final finally float for function goto if implements import in instanceof int interface let long native new null package private protected public return short static super switch synchronized this throw throws transient true try typeof var void volatile while with yield'.split( ' ' );
|
9
|
+
const blacklist = { __esModule: true };
|
10
|
+
reserved.forEach( word => blacklist[ word ] = true );
|
11
|
+
|
12
|
+
const exportsPattern = /^(?:module\.)?exports(?:\.([a-zA-Z_$][a-zA-Z_$0-9]*))?$/;
|
13
|
+
|
14
|
+
const firstpassGlobal = /\b(?:require|module|exports|global)\b/;
|
15
|
+
const firstpassNoGlobal = /\b(?:require|module|exports)\b/;
|
16
|
+
const importExportDeclaration = /^(?:Import|Export(?:Named|Default))Declaration/;
|
17
|
+
const functionType = /^(?:FunctionDeclaration|FunctionExpression|ArrowFunctionExpression)$/;
|
18
|
+
|
19
|
+
function deconflict ( scope, globals, identifier ) {
|
20
|
+
let i = 1;
|
21
|
+
let deconflicted = identifier;
|
22
|
+
|
23
|
+
while ( scope.contains( deconflicted ) || globals.has( deconflicted ) || deconflicted in blacklist ) deconflicted = `${identifier}_${i++}`;
|
24
|
+
scope.declarations[ deconflicted ] = true;
|
25
|
+
|
26
|
+
return deconflicted;
|
27
|
+
}
|
28
|
+
|
29
|
+
function tryParse ( parse, code, id ) {
|
30
|
+
try {
|
31
|
+
return parse( code, { allowReturnOutsideFunction: true });
|
32
|
+
} catch ( err ) {
|
33
|
+
err.message += ` in ${id}`;
|
34
|
+
throw err;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
export function checkFirstpass (code, ignoreGlobal) {
|
39
|
+
const firstpass = ignoreGlobal ? firstpassNoGlobal : firstpassGlobal;
|
40
|
+
return firstpass.test(code);
|
41
|
+
}
|
42
|
+
|
43
|
+
export function checkEsModule ( parse, code, id ) {
|
44
|
+
const ast = tryParse( parse, code, id );
|
45
|
+
|
46
|
+
// if there are top-level import/export declarations, this is ES not CommonJS
|
47
|
+
let hasDefaultExport = false;
|
48
|
+
let isEsModule = false;
|
49
|
+
for ( const node of ast.body ) {
|
50
|
+
if ( node.type === 'ExportDefaultDeclaration' )
|
51
|
+
hasDefaultExport = true;
|
52
|
+
if ( importExportDeclaration.test( node.type ) )
|
53
|
+
isEsModule = true;
|
54
|
+
}
|
55
|
+
|
56
|
+
return { isEsModule, hasDefaultExport, ast };
|
57
|
+
}
|
58
|
+
|
59
|
+
export function transformCommonjs ( parse, code, id, isEntry, ignoreGlobal, ignoreRequire, customNamedExports, sourceMap, allowDynamicRequire, astCache ) {
|
60
|
+
const ast = astCache || tryParse( parse, code, id );
|
61
|
+
|
62
|
+
const magicString = new MagicString( code );
|
63
|
+
|
64
|
+
const required = {};
|
65
|
+
// Because objects have no guaranteed ordering, yet we need it,
|
66
|
+
// we need to keep track of the order in a array
|
67
|
+
const sources = [];
|
68
|
+
|
69
|
+
let uid = 0;
|
70
|
+
|
71
|
+
let scope = attachScopes( ast, 'scope' );
|
72
|
+
const uses = { module: false, exports: false, global: false, require: false };
|
73
|
+
|
74
|
+
let lexicalDepth = 0;
|
75
|
+
let programDepth = 0;
|
76
|
+
|
77
|
+
const globals = new Set();
|
78
|
+
|
79
|
+
const HELPERS_NAME = deconflict( scope, globals, 'commonjsHelpers' ); // TODO technically wrong since globals isn't populated yet, but ¯\_(ツ)_/¯
|
80
|
+
|
81
|
+
const namedExports = {};
|
82
|
+
|
83
|
+
// TODO handle transpiled modules
|
84
|
+
let shouldWrap = /__esModule/.test( code );
|
85
|
+
|
86
|
+
function isRequireStatement ( node ) {
|
87
|
+
if ( !node ) return;
|
88
|
+
if ( node.type !== 'CallExpression' ) return;
|
89
|
+
if ( node.callee.name !== 'require' || scope.contains( 'require' ) ) return;
|
90
|
+
if ( node.arguments.length !== 1 || (node.arguments[0].type !== 'Literal' && (node.arguments[0].type !== 'TemplateLiteral' || node.arguments[0].expressions.length > 0) ) ) return; // TODO handle these weird cases?
|
91
|
+
if ( ignoreRequire( node.arguments[0].value ) ) return;
|
92
|
+
|
93
|
+
return true;
|
94
|
+
}
|
95
|
+
|
96
|
+
function getRequired ( node, name ) {
|
97
|
+
const source = node.arguments[0].type === 'Literal' ? node.arguments[0].value : node.arguments[0].quasis[0].value.cooked;
|
98
|
+
|
99
|
+
const existing = required[ source ];
|
100
|
+
if ( existing === undefined ) {
|
101
|
+
sources.push( source );
|
102
|
+
|
103
|
+
if ( !name ) {
|
104
|
+
do name = `require$$${uid++}`;
|
105
|
+
while ( scope.contains( name ) );
|
106
|
+
}
|
107
|
+
|
108
|
+
required[ source ] = { source, name, importsDefault: false };
|
109
|
+
}
|
110
|
+
|
111
|
+
return required[ source ];
|
112
|
+
}
|
113
|
+
|
114
|
+
// do a first pass, see which names are assigned to. This is necessary to prevent
|
115
|
+
// illegally replacing `var foo = require('foo')` with `import foo from 'foo'`,
|
116
|
+
// where `foo` is later reassigned. (This happens in the wild. CommonJS, sigh)
|
117
|
+
const assignedTo = new Set();
|
118
|
+
walk( ast, {
|
119
|
+
enter ( node ) {
|
120
|
+
if ( node.type !== 'AssignmentExpression' ) return;
|
121
|
+
if ( node.left.type === 'MemberExpression' ) return;
|
122
|
+
|
123
|
+
extractNames( node.left ).forEach( name => {
|
124
|
+
assignedTo.add( name );
|
125
|
+
});
|
126
|
+
}
|
127
|
+
});
|
128
|
+
|
129
|
+
walk( ast, {
|
130
|
+
enter ( node, parent ) {
|
131
|
+
if ( sourceMap ) {
|
132
|
+
magicString.addSourcemapLocation( node.start );
|
133
|
+
magicString.addSourcemapLocation( node.end );
|
134
|
+
}
|
135
|
+
|
136
|
+
// skip dead branches
|
137
|
+
if ( parent && ( parent.type === 'IfStatement' || parent.type === 'ConditionalExpression' ) ) {
|
138
|
+
if ( node === parent.consequent && isFalsy( parent.test ) ) return this.skip();
|
139
|
+
if ( node === parent.alternate && isTruthy( parent.test ) ) return this.skip();
|
140
|
+
}
|
141
|
+
|
142
|
+
if ( node._skip ) return this.skip();
|
143
|
+
|
144
|
+
programDepth += 1;
|
145
|
+
|
146
|
+
if ( node.scope ) scope = node.scope;
|
147
|
+
if ( functionType.test( node.type ) ) lexicalDepth += 1;
|
148
|
+
|
149
|
+
// if toplevel return, we need to wrap it
|
150
|
+
if ( node.type === 'ReturnStatement' && lexicalDepth === 0 ) {
|
151
|
+
shouldWrap = true;
|
152
|
+
}
|
153
|
+
|
154
|
+
// rewrite `this` as `commonjsHelpers.commonjsGlobal`
|
155
|
+
if ( node.type === 'ThisExpression' && lexicalDepth === 0 ) {
|
156
|
+
uses.global = true;
|
157
|
+
if ( !ignoreGlobal ) magicString.overwrite( node.start, node.end, `${HELPERS_NAME}.commonjsGlobal`, { storeName: true } );
|
158
|
+
return;
|
159
|
+
}
|
160
|
+
|
161
|
+
// rewrite `typeof module`, `typeof module.exports` and `typeof exports` (https://github.com/rollup/rollup-plugin-commonjs/issues/151)
|
162
|
+
if ( node.type === 'UnaryExpression' && node.operator === 'typeof' ) {
|
163
|
+
const flattened = flatten( node.argument );
|
164
|
+
if ( !flattened ) return;
|
165
|
+
|
166
|
+
if ( scope.contains( flattened.name ) ) return;
|
167
|
+
|
168
|
+
if ( flattened.keypath === 'module.exports' || flattened.keypath === 'module' || flattened.keypath === 'exports' ) {
|
169
|
+
magicString.overwrite( node.start, node.end, `'object'`, { storeName: false } );
|
170
|
+
}
|
171
|
+
}
|
172
|
+
|
173
|
+
// rewrite `require` (if not already handled) `global` and `define`, and handle free references to
|
174
|
+
// `module` and `exports` as these mean we need to wrap the module in commonjsHelpers.createCommonjsModule
|
175
|
+
if ( node.type === 'Identifier' ) {
|
176
|
+
if ( isReference( node, parent ) && !scope.contains( node.name ) ) {
|
177
|
+
if ( node.name in uses ) {
|
178
|
+
if ( node.name === 'require' ) {
|
179
|
+
if ( allowDynamicRequire ) return;
|
180
|
+
magicString.overwrite( node.start, node.end, `${HELPERS_NAME}.commonjsRequire`, { storeName: true } );
|
181
|
+
}
|
182
|
+
|
183
|
+
uses[ node.name ] = true;
|
184
|
+
if ( node.name === 'global' && !ignoreGlobal ) {
|
185
|
+
magicString.overwrite( node.start, node.end, `${HELPERS_NAME}.commonjsGlobal`, { storeName: true } );
|
186
|
+
}
|
187
|
+
|
188
|
+
// if module or exports are used outside the context of an assignment
|
189
|
+
// expression, we need to wrap the module
|
190
|
+
if ( node.name === 'module' || node.name === 'exports' ) {
|
191
|
+
shouldWrap = true;
|
192
|
+
}
|
193
|
+
}
|
194
|
+
|
195
|
+
if ( node.name === 'define' ) {
|
196
|
+
magicString.overwrite( node.start, node.end, 'undefined', { storeName: true } );
|
197
|
+
}
|
198
|
+
|
199
|
+
globals.add( node.name );
|
200
|
+
}
|
201
|
+
|
202
|
+
return;
|
203
|
+
}
|
204
|
+
|
205
|
+
// Is this an assignment to exports or module.exports?
|
206
|
+
if ( node.type === 'AssignmentExpression' ) {
|
207
|
+
if ( node.left.type !== 'MemberExpression' ) return;
|
208
|
+
|
209
|
+
const flattened = flatten( node.left );
|
210
|
+
if ( !flattened ) return;
|
211
|
+
|
212
|
+
if ( scope.contains( flattened.name ) ) return;
|
213
|
+
|
214
|
+
const match = exportsPattern.exec( flattened.keypath );
|
215
|
+
if ( !match || flattened.keypath === 'exports' ) return;
|
216
|
+
|
217
|
+
uses[ flattened.name ] = true;
|
218
|
+
|
219
|
+
// we're dealing with `module.exports = ...` or `[module.]exports.foo = ...` –
|
220
|
+
// if this isn't top-level, we'll need to wrap the module
|
221
|
+
if ( programDepth > 3 ) shouldWrap = true;
|
222
|
+
|
223
|
+
node.left._skip = true;
|
224
|
+
|
225
|
+
if ( flattened.keypath === 'module.exports' && node.right.type === 'ObjectExpression' ) {
|
226
|
+
return node.right.properties.forEach( prop => {
|
227
|
+
if ( prop.computed || prop.key.type !== 'Identifier' ) return;
|
228
|
+
const name = prop.key.name;
|
229
|
+
if ( name === makeLegalIdentifier( name ) ) namedExports[ name ] = true;
|
230
|
+
});
|
231
|
+
}
|
232
|
+
|
233
|
+
if ( match[1] ) namedExports[ match[1] ] = true;
|
234
|
+
return;
|
235
|
+
}
|
236
|
+
|
237
|
+
// if this is `var x = require('x')`, we can do `import x from 'x'`
|
238
|
+
if ( node.type === 'VariableDeclarator' && node.id.type === 'Identifier' && isRequireStatement( node.init ) ) {
|
239
|
+
// for now, only do this for top-level requires. maybe fix this in future
|
240
|
+
if ( scope.parent ) return;
|
241
|
+
|
242
|
+
// edge case — CJS allows you to assign to imports. ES doesn't
|
243
|
+
if ( assignedTo.has( node.id.name ) ) return;
|
244
|
+
|
245
|
+
const r = getRequired( node.init, node.id.name );
|
246
|
+
r.importsDefault = true;
|
247
|
+
|
248
|
+
if ( r.name === node.id.name ) {
|
249
|
+
node._shouldRemove = true;
|
250
|
+
}
|
251
|
+
}
|
252
|
+
|
253
|
+
if ( !isRequireStatement( node ) ) return;
|
254
|
+
|
255
|
+
const r = getRequired( node );
|
256
|
+
|
257
|
+
if ( parent.type === 'ExpressionStatement' ) {
|
258
|
+
// is a bare import, e.g. `require('foo');`
|
259
|
+
magicString.remove( parent.start, parent.end );
|
260
|
+
} else {
|
261
|
+
r.importsDefault = true;
|
262
|
+
magicString.overwrite( node.start, node.end, r.name );
|
263
|
+
}
|
264
|
+
|
265
|
+
node.callee._skip = true;
|
266
|
+
},
|
267
|
+
|
268
|
+
leave ( node ) {
|
269
|
+
programDepth -= 1;
|
270
|
+
if ( node.scope ) scope = scope.parent;
|
271
|
+
if ( functionType.test( node.type ) ) lexicalDepth -= 1;
|
272
|
+
|
273
|
+
if ( node.type === 'VariableDeclaration' ) {
|
274
|
+
let keepDeclaration = false;
|
275
|
+
let c = node.declarations[0].start;
|
276
|
+
|
277
|
+
for ( let i = 0; i < node.declarations.length; i += 1 ) {
|
278
|
+
const declarator = node.declarations[i];
|
279
|
+
|
280
|
+
if ( declarator._shouldRemove ) {
|
281
|
+
magicString.remove( c, declarator.end );
|
282
|
+
} else {
|
283
|
+
if ( !keepDeclaration ) {
|
284
|
+
magicString.remove( c, declarator.start );
|
285
|
+
keepDeclaration = true;
|
286
|
+
}
|
287
|
+
|
288
|
+
c = declarator.end;
|
289
|
+
}
|
290
|
+
}
|
291
|
+
|
292
|
+
if ( !keepDeclaration ) {
|
293
|
+
magicString.remove( node.start, node.end );
|
294
|
+
}
|
295
|
+
}
|
296
|
+
}
|
297
|
+
});
|
298
|
+
|
299
|
+
if ( !sources.length && !uses.module && !uses.exports && !uses.require && ( ignoreGlobal || !uses.global ) ) {
|
300
|
+
if ( Object.keys( namedExports ).length ) {
|
301
|
+
throw new Error( `Custom named exports were specified for ${id} but it does not appear to be a CommonJS module` );
|
302
|
+
}
|
303
|
+
return null; // not a CommonJS module
|
304
|
+
}
|
305
|
+
|
306
|
+
const includeHelpers = shouldWrap || uses.global || uses.require;
|
307
|
+
const importBlock = ( includeHelpers ? [ `import * as ${HELPERS_NAME} from '${HELPERS_ID}';` ] : [] ).concat(
|
308
|
+
sources.map( source => {
|
309
|
+
// import the actual module before the proxy, so that we know
|
310
|
+
// what kind of proxy to build
|
311
|
+
return `import '${source}';`;
|
312
|
+
}),
|
313
|
+
sources.map( source => {
|
314
|
+
const { name, importsDefault } = required[ source ];
|
315
|
+
return `import ${importsDefault ? `${name} from ` : ``}'${PREFIX}${source}';`;
|
316
|
+
})
|
317
|
+
).join( '\n' ) + '\n\n';
|
318
|
+
|
319
|
+
const namedExportDeclarations = [];
|
320
|
+
let wrapperStart = '';
|
321
|
+
let wrapperEnd = '';
|
322
|
+
|
323
|
+
const moduleName = deconflict( scope, globals, getName( id ) );
|
324
|
+
if ( !isEntry ) {
|
325
|
+
const exportModuleExports = {
|
326
|
+
str: `export { ${moduleName} as __moduleExports };`,
|
327
|
+
name: '__moduleExports'
|
328
|
+
};
|
329
|
+
|
330
|
+
namedExportDeclarations.push( exportModuleExports );
|
331
|
+
}
|
332
|
+
|
333
|
+
const name = getName( id );
|
334
|
+
|
335
|
+
function addExport ( x ) {
|
336
|
+
const deconflicted = deconflict( scope, globals, name );
|
337
|
+
|
338
|
+
const declaration = deconflicted === name ?
|
339
|
+
`export var ${x} = ${moduleName}.${x};` :
|
340
|
+
`var ${deconflicted} = ${moduleName}.${x};\nexport { ${deconflicted} as ${x} };`;
|
341
|
+
|
342
|
+
namedExportDeclarations.push({
|
343
|
+
str: declaration,
|
344
|
+
name: x
|
345
|
+
});
|
346
|
+
}
|
347
|
+
|
348
|
+
if ( customNamedExports ) customNamedExports.forEach( addExport );
|
349
|
+
|
350
|
+
const defaultExportPropertyAssignments = [];
|
351
|
+
let hasDefaultExport = false;
|
352
|
+
|
353
|
+
if ( shouldWrap ) {
|
354
|
+
const args = `module${uses.exports ? ', exports' : ''}`;
|
355
|
+
|
356
|
+
wrapperStart = `var ${moduleName} = ${HELPERS_NAME}.createCommonjsModule(function (${args}) {\n`;
|
357
|
+
wrapperEnd = `\n});`;
|
358
|
+
} else {
|
359
|
+
const names = [];
|
360
|
+
|
361
|
+
ast.body.forEach( node => {
|
362
|
+
if ( node.type === 'ExpressionStatement' && node.expression.type === 'AssignmentExpression' ) {
|
363
|
+
const left = node.expression.left;
|
364
|
+
const flattened = flatten( left );
|
365
|
+
|
366
|
+
if ( !flattened ) return;
|
367
|
+
|
368
|
+
const match = exportsPattern.exec( flattened.keypath );
|
369
|
+
if ( !match ) return;
|
370
|
+
|
371
|
+
if ( flattened.keypath === 'module.exports' ) {
|
372
|
+
hasDefaultExport = true;
|
373
|
+
magicString.overwrite( left.start, left.end, `var ${moduleName}` );
|
374
|
+
} else {
|
375
|
+
const name = match[1];
|
376
|
+
const deconflicted = deconflict( scope, globals, name );
|
377
|
+
|
378
|
+
names.push({ name, deconflicted });
|
379
|
+
|
380
|
+
magicString.overwrite( node.start, left.end, `var ${deconflicted}` );
|
381
|
+
|
382
|
+
const declaration = name === deconflicted ?
|
383
|
+
`export { ${name} };` :
|
384
|
+
`export { ${deconflicted} as ${name} };`;
|
385
|
+
|
386
|
+
if ( name !== 'default' ) {
|
387
|
+
namedExportDeclarations.push({
|
388
|
+
str: declaration,
|
389
|
+
name
|
390
|
+
});
|
391
|
+
delete namedExports[name];
|
392
|
+
}
|
393
|
+
|
394
|
+
defaultExportPropertyAssignments.push( `${moduleName}.${name} = ${deconflicted};` );
|
395
|
+
}
|
396
|
+
}
|
397
|
+
});
|
398
|
+
|
399
|
+
if ( !hasDefaultExport ) {
|
400
|
+
wrapperEnd = `\n\nvar ${moduleName} = {\n${
|
401
|
+
names.map( ({ name, deconflicted }) => `\t${name}: ${deconflicted}` ).join( ',\n' )
|
402
|
+
}\n};`;
|
403
|
+
}
|
404
|
+
}
|
405
|
+
Object.keys( namedExports )
|
406
|
+
.filter( key => !blacklist[ key ] )
|
407
|
+
.forEach( addExport );
|
408
|
+
|
409
|
+
const defaultExport = /__esModule/.test( code ) ?
|
410
|
+
`export default ${HELPERS_NAME}.unwrapExports(${moduleName});` :
|
411
|
+
`export default ${moduleName};`;
|
412
|
+
|
413
|
+
const named = namedExportDeclarations
|
414
|
+
.filter( x => x.name !== 'default' || !hasDefaultExport )
|
415
|
+
.map( x => x.str );
|
416
|
+
|
417
|
+
const exportBlock = '\n\n' + [ defaultExport ]
|
418
|
+
.concat( named )
|
419
|
+
.concat( hasDefaultExport ? defaultExportPropertyAssignments : [] )
|
420
|
+
.join( '\n' );
|
421
|
+
|
422
|
+
magicString.trim()
|
423
|
+
.prepend( importBlock + wrapperStart )
|
424
|
+
.trim()
|
425
|
+
.append( wrapperEnd + exportBlock );
|
426
|
+
|
427
|
+
code = magicString.toString();
|
428
|
+
const map = sourceMap ? magicString.generateMap() : null;
|
429
|
+
|
430
|
+
return { code, map };
|
431
|
+
}
|