├── .github ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── disable_workflows │ └── codecoverage.yml └── workflows │ └── test.yml ├── .gitignore ├── LICENSE ├── README.md ├── package.json ├── renovate.json ├── rollup.config.js ├── src ├── acorn-walk.d.ts ├── acorn.ts ├── compiler.ts ├── debug.ts ├── google-closure-compiler.d.ts ├── index.ts ├── options.ts ├── parsing │ ├── export-details.ts │ ├── import-specifiers.ts │ ├── literal-name.ts │ ├── preserve-default-export.ts │ └── preserve-named-constant-export.ts ├── source-map.ts ├── temp-file.ts ├── transform.ts ├── transformers │ ├── chunk │ │ ├── asi.ts │ │ ├── cjs.ts │ │ ├── const.ts │ │ ├── exports.ts │ │ ├── hashbang-apply.ts │ │ ├── hashbang-remove.ts │ │ ├── iife.ts │ │ ├── imports.ts │ │ ├── literal-computed-keys.ts │ │ ├── strict.ts │ │ └── transforms.ts │ ├── ebbinghaus.ts │ ├── mangle.ts │ └── source │ │ ├── exports.ts │ │ ├── hashbang.ts │ │ ├── imports.ts │ │ └── transforms.ts └── types.ts ├── test ├── arrow-function │ ├── fixtures │ │ ├── multiple-arguments.esm.advanced.js │ │ ├── multiple-arguments.esm.default.js │ │ ├── multiple-arguments.esm.es5.js │ │ ├── multiple-arguments.esm.pretty.js │ │ ├── multiple-arguments.js │ │ ├── single-argument.esm.advanced.js │ │ ├── single-argument.esm.default.js │ │ ├── single-argument.esm.es5.js │ │ ├── single-argument.esm.pretty.js │ │ └── single-argument.js │ ├── multiple-arguments.test.js │ └── single-argument.test.js ├── closure-config │ ├── fixtures │ │ ├── externs.js │ │ ├── prefer-config.esm.javascript.js │ │ └── prefer-config.js │ ├── prefer-config.test.js │ ├── rollup-config-externs.test.js │ ├── rollup-config-to-flags.test.js │ └── warning-level.test.js ├── const-rename │ ├── fixtures │ │ ├── rename.esm.advanced.js │ │ ├── rename.esm.default.js │ │ ├── rename.esm.es5.js │ │ ├── rename.esm.pretty.js │ │ └── rename.js │ └── rename.test.js ├── error-reporting │ ├── fixtures │ │ ├── warnings.esm.advanced.js │ │ ├── warnings.esm.default.js │ │ ├── warnings.esm.es5.js │ │ └── warnings.js │ └── warnings.test.js ├── export-all │ ├── all-external.test.js │ ├── all.test.js │ └── fixtures │ │ ├── all-external.esm.default.js │ │ ├── all-external.js │ │ ├── all.esm.advanced.js │ │ ├── all.esm.default.js │ │ ├── all.esm.es5.js │ │ ├── all.esm.pretty.js │ │ ├── all.js │ │ ├── dep.js │ │ └── external.js ├── export-cjs │ ├── export-cjs-extern.test.js │ └── fixtures │ │ └── export.extern.js ├── export-default │ ├── array.test.js │ ├── arrow-function.test.js │ ├── class.test.js │ ├── fixtures │ │ ├── array.esm.advanced.js │ │ ├── array.esm.default.js │ │ ├── array.esm.es5.js │ │ ├── array.esm.pretty.js │ │ ├── array.js │ │ ├── arrow-function.esm.advanced.js │ │ ├── arrow-function.esm.default.js │ │ ├── arrow-function.esm.es5.js │ │ ├── arrow-function.esm.pretty.js │ │ ├── arrow-function.js │ │ ├── class.esm.advanced.js │ │ ├── class.esm.default.js │ │ ├── class.esm.es5.js │ │ ├── class.esm.pretty.js │ │ ├── class.js │ │ ├── function.esm.advanced.js │ │ ├── function.esm.default.js │ │ ├── function.esm.es5.js │ │ ├── function.esm.pretty.js │ │ ├── function.js │ │ ├── identifier.esm.advanced.js │ │ ├── identifier.esm.default.js │ │ ├── identifier.esm.es5.js │ │ ├── identifier.esm.pretty.js │ │ ├── identifier.js │ │ ├── named-class.esm.advanced.js │ │ ├── named-class.esm.default.js │ │ ├── named-class.esm.es5.js │ │ ├── named-class.esm.pretty.js │ │ ├── named-class.js │ │ ├── named-function.esm.advanced.js │ │ ├── named-function.esm.default.js │ │ ├── named-function.esm.es5.js │ │ ├── named-function.esm.pretty.js │ │ ├── named-function.js │ │ ├── number.esm.advanced.js │ │ ├── number.esm.default.js │ │ ├── number.esm.es5.js │ │ ├── number.esm.pretty.js │ │ ├── number.js │ │ ├── object.esm.advanced.js │ │ ├── object.esm.default.js │ │ ├── object.esm.es5.js │ │ ├── object.esm.pretty.js │ │ └── object.js │ ├── function.test.js │ ├── identifier.test.js │ ├── named-class.test.js │ ├── named-function.test.js │ ├── number.test.js │ └── object.test.js ├── export-externals │ ├── array.test.js │ ├── class.test.js │ ├── const-function.test.js │ ├── const-number.test.js │ ├── default.test.js │ ├── fixtures │ │ ├── array.esm.advanced.js │ │ ├── array.esm.default.js │ │ ├── array.esm.es5.js │ │ ├── array.esm.pretty.js │ │ ├── array.js │ │ ├── class.esm.advanced.js │ │ ├── class.esm.default.js │ │ ├── class.esm.es5.js │ │ ├── class.esm.pretty.js │ │ ├── class.js │ │ ├── const-function.esm.advanced.js │ │ ├── const-function.esm.default.js │ │ ├── const-function.esm.es5.js │ │ ├── const-function.esm.pretty.js │ │ ├── const-function.js │ │ ├── const-number.esm.advanced.js │ │ ├── const-number.esm.default.js │ │ ├── const-number.esm.es5.js │ │ ├── const-number.esm.pretty.js │ │ ├── const-number.js │ │ ├── default.esm.advanced.js │ │ ├── default.esm.default.js │ │ ├── default.esm.es5.js │ │ ├── default.esm.pretty.js │ │ ├── default.js │ │ ├── external-default.js │ │ ├── external.js │ │ ├── function.esm.advanced.js │ │ ├── function.esm.default.js │ │ ├── function.esm.es5.js │ │ ├── function.esm.pretty.js │ │ ├── function.js │ │ ├── local.esm.advanced.js │ │ ├── local.esm.default.js │ │ ├── local.esm.es5.js │ │ ├── local.esm.pretty.js │ │ ├── local.js │ │ ├── multiple-default.esm.advanced.js │ │ ├── multiple-default.esm.default.js │ │ ├── multiple-default.esm.es5.js │ │ ├── multiple-default.esm.pretty.js │ │ ├── multiple-default.js │ │ ├── object.esm.advanced.js │ │ ├── object.esm.default.js │ │ ├── object.esm.es5.js │ │ ├── object.esm.pretty.js │ │ ├── object.js │ │ ├── reserve-local-name.esm.advanced.js │ │ ├── reserve-local-name.esm.default.js │ │ ├── reserve-local-name.esm.es5.js │ │ ├── reserve-local-name.esm.pretty.js │ │ └── reserve-local-name.js │ ├── function.test.js │ ├── local.test.js │ ├── multiple-default.test.js │ ├── object.test.js │ └── reserve-local-name.test.js ├── export-named │ ├── fixtures │ │ ├── identifier-alias.esm.advanced.js │ │ ├── identifier-alias.esm.default.js │ │ ├── identifier-alias.esm.es5.js │ │ ├── identifier-alias.esm.pretty.js │ │ ├── identifier-alias.js │ │ ├── identifier-default.esm.advanced.js │ │ ├── identifier-default.esm.default.js │ │ ├── identifier-default.esm.es5.js │ │ ├── identifier-default.esm.pretty.js │ │ ├── identifier-default.js │ │ ├── identifier.esm.advanced.js │ │ ├── identifier.esm.default.js │ │ ├── identifier.esm.es5.js │ │ ├── identifier.esm.pretty.js │ │ ├── identifier.js │ │ ├── multiple.esm.advanced.js │ │ ├── multiple.esm.default.js │ │ ├── multiple.esm.es5.js │ │ ├── multiple.esm.pretty.js │ │ └── multiple.js │ ├── identifier-alias.test.js │ ├── identifier-default.test.js │ ├── identifier.test.js │ └── multiple.test.js ├── export-transpilation │ ├── fixtures │ │ ├── named-constant.esm.advanced.js │ │ ├── named-constant.esm.default.js │ │ ├── named-constant.esm.es5.js │ │ ├── named-constant.esm.pretty.js │ │ ├── named-constant.js │ │ ├── named-function.esm.advanced.js │ │ ├── named-function.esm.default.js │ │ ├── named-function.esm.es5.js │ │ ├── named-function.esm.pretty.js │ │ └── named-function.js │ ├── named-constant.test.js │ └── named-function.test.js ├── export-variables │ ├── class.test.js │ ├── const-function.test.js │ ├── const-number.test.js │ ├── fixtures │ │ ├── class.esm.advanced.js │ │ ├── class.esm.default.js │ │ ├── class.esm.es5.js │ │ ├── class.esm.pretty.js │ │ ├── class.js │ │ ├── const-function.esm.advanced.js │ │ ├── const-function.esm.default.js │ │ ├── const-function.esm.es5.js │ │ ├── const-function.esm.pretty.js │ │ ├── const-function.js │ │ ├── const-number.esm.advanced.js │ │ ├── const-number.esm.default.js │ │ ├── const-number.esm.es5.js │ │ ├── const-number.esm.pretty.js │ │ ├── const-number.js │ │ ├── function.esm.advanced.js │ │ ├── function.esm.default.js │ │ ├── function.esm.es5.js │ │ ├── function.esm.pretty.js │ │ ├── function.js │ │ ├── let-function.esm.advanced.js │ │ ├── let-function.esm.default.js │ │ ├── let-function.esm.es5.js │ │ ├── let-function.esm.pretty.js │ │ ├── let-function.js │ │ ├── let-identifier.esm.advanced.js │ │ ├── let-identifier.esm.default.js │ │ ├── let-identifier.esm.es5.js │ │ ├── let-identifier.esm.pretty.js │ │ ├── let-identifier.js │ │ ├── let-number.esm.advanced.js │ │ ├── let-number.esm.default.js │ │ ├── let-number.esm.es5.js │ │ ├── let-number.esm.pretty.js │ │ ├── let-number.js │ │ ├── var-function.esm.advanced.js │ │ ├── var-function.esm.default.js │ │ ├── var-function.esm.es5.js │ │ ├── var-function.esm.pretty.js │ │ ├── var-function.js │ │ ├── var-identifier.esm.advanced.js │ │ ├── var-identifier.esm.default.js │ │ ├── var-identifier.esm.es5.js │ │ ├── var-identifier.esm.pretty.js │ │ ├── var-identifier.js │ │ ├── var-number.esm.advanced.js │ │ ├── var-number.esm.default.js │ │ ├── var-number.esm.es5.js │ │ ├── var-number.esm.pretty.js │ │ └── var-number.js │ ├── function.test.js │ ├── let-function.test.js │ ├── let-identifier.test.js │ ├── let-number.test.js │ ├── var-function.test.js │ ├── var-identifier.test.js │ └── var-number.test.js ├── generator.js ├── hashbang │ ├── fixtures │ │ ├── hashbang-banner.esm.advanced.js │ │ ├── hashbang-banner.esm.default.js │ │ ├── hashbang-banner.esm.es5.js │ │ ├── hashbang-banner.esm.pretty.js │ │ ├── hashbang-banner.js │ │ ├── hashbang-preserved.esm.advanced.js │ │ ├── hashbang-preserved.esm.default.js │ │ ├── hashbang-preserved.esm.es5.js │ │ ├── hashbang-preserved.esm.pretty.js │ │ └── hashbang-preserved.js │ ├── hashbang-banner.test.js │ └── hashbang-preserved.test.js ├── iife │ ├── fixtures │ │ ├── iife-wrapped-safely.iife.advanced.js │ │ ├── iife-wrapped-safely.iife.default.js │ │ ├── iife-wrapped-safely.iife.es5.js │ │ ├── iife-wrapped-safely.iife.pretty.js │ │ ├── iife-wrapped-safely.js │ │ └── iife.extern.js │ └── iife-wrapped-safely.test.js ├── import │ ├── dynamic.test.js │ ├── external.test.js │ ├── fixtures │ │ ├── chunk-5275c9cc.esm.default.js │ │ ├── dynamic-imported-67216f69.esm.advanced.js │ │ ├── dynamic-imported-67216f69.esm.default.js │ │ ├── dynamic-imported-67216f69.esm.es5.js │ │ ├── dynamic-imported-67216f69.esm.pretty.js │ │ ├── dynamic-imported.js │ │ ├── dynamic.esm.advanced.js │ │ ├── dynamic.esm.default.js │ │ ├── dynamic.esm.es5.js │ │ ├── dynamic.esm.pretty.js │ │ ├── dynamic.js │ │ ├── external.esm.advanced.js │ │ ├── external.esm.default.js │ │ ├── external.esm.es5.js │ │ ├── external.esm.pretty.js │ │ ├── external.js │ │ ├── flattened.esm.advanced.js │ │ ├── flattened.esm.default.js │ │ ├── flattened.esm.es5.js │ │ ├── flattened.esm.pretty.js │ │ ├── flattened.js │ │ ├── imported.js │ │ ├── star.esm.advanced.js │ │ ├── star.esm.default.js │ │ ├── star.esm.es5.js │ │ ├── star.esm.pretty.js │ │ ├── star.js │ │ ├── utf8-41b27160.esm.advanced.js │ │ ├── utf8-41b27160.esm.default.js │ │ ├── utf8-41b27160.esm.es5.js │ │ ├── utf8-41b27160.esm.pretty.js │ │ ├── utf8-common-38fdc940.esm.advanced.js │ │ ├── utf8-common-38fdc940.esm.default.js │ │ ├── utf8-common-38fdc940.esm.es5.js │ │ ├── utf8-common-38fdc940.esm.pretty.js │ │ ├── utf8-common.js │ │ ├── utf8-lazy-527020b7.esm.advanced.js │ │ ├── utf8-lazy-527020b7.esm.default.js │ │ ├── utf8-lazy-527020b7.esm.es5.js │ │ ├── utf8-lazy-527020b7.esm.pretty.js │ │ ├── utf8-lazy.js │ │ ├── utf8.esm.advanced.js │ │ ├── utf8.esm.default.js │ │ ├── utf8.esm.es5.js │ │ ├── utf8.esm.pretty.js │ │ └── utf8.js │ ├── flattened.test.js │ ├── star.test.js │ └── utf8.test.js ├── literal-computed-keys │ ├── fixtures │ │ ├── literal-computed.esm.advanced.js │ │ ├── literal-computed.esm.default.js │ │ ├── literal-computed.esm.es5.js │ │ ├── literal-computed.esm.pretty.js │ │ ├── literal-computed.js │ │ ├── mixed-keys.esm.advanced.js │ │ ├── mixed-keys.esm.default.js │ │ ├── mixed-keys.esm.es5.js │ │ ├── mixed-keys.esm.pretty.js │ │ ├── mixed-keys.js │ │ ├── spread-expression.esm.advanced.js │ │ ├── spread-expression.esm.default.js │ │ ├── spread-expression.esm.es5.js │ │ ├── spread-expression.esm.pretty.js │ │ └── spread-expression.js │ ├── literal-computed.test.js │ ├── mixed-keys.test.js │ └── spread-expression.test.js ├── mangle │ ├── fixtures │ │ ├── reassign-arrow.esm.default.js │ │ ├── reassign-arrow.js │ │ ├── reassign-function.esm.default.js │ │ ├── reassign-function.js │ │ └── test-function.js │ ├── reassign-arrow.test.js │ └── reassign-function.test.js ├── provided-externs │ ├── class.test.js │ ├── fixtures │ │ ├── class.esm.advanced.js │ │ ├── class.esm.default.js │ │ ├── class.esm.es5.js │ │ ├── class.esm.pretty.js │ │ ├── class.externs.js │ │ └── class.js │ └── multiple-bundles.test.js └── strict-removal │ ├── fixtures │ ├── mjs-suffix.iife.default.mjs │ ├── mjs-suffix.mjs │ ├── option.iife.default.js │ ├── option.js │ ├── top-level.esm.advanced.js │ ├── top-level.esm.default.js │ ├── top-level.esm.es5.js │ ├── top-level.esm.pretty.js │ └── top-level.js │ ├── mjs-suffix.test.js │ ├── option.test.js │ └── top-level.test.js ├── tsconfig.json ├── tsconfig.test.json └── yarn.lock /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | See https://github.com/ampproject/meta/blob/master/CODE_OF_CONDUCT.md 2 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | We'd love to accept your patches and contributions to this project. There are 4 | just a few small guidelines you need to follow. 5 | 6 | ## Contributor License Agreement 7 | 8 | Contributions to this project must be accompanied by a Contributor License 9 | Agreement. You (or your employer) retain the copyright to your contribution; 10 | this simply gives us permission to use and redistribute your contributions as 11 | part of the project. Head over to to see 12 | your current agreements on file or to sign a new one. 13 | 14 | You generally only need to submit a CLA once, so if you've already submitted one 15 | (even if it was for a different project), you probably don't need to do it 16 | again. 17 | 18 | ## Code reviews 19 | 20 | All submissions, including submissions by project members, require review. We 21 | use GitHub pull requests for this purpose. Consult 22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more 23 | information on using pull requests. 24 | 25 | ## Community Guidelines 26 | 27 | The AMP Project strives for a positive and growing project community that provides a safe environment for everyone. All members, committers and volunteers in the community are required to act according to the [code of conduct](CODE_OF_CONDUCT.md). -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | 5 | --- 6 | 7 | **Please only file bugs/feature requests for rollup-plugin-closure-compiler here.** 8 | 9 | - If you have questions about how to use AMP or other general questions about AMP please ask them on Stack Overflow under the AMP HTML tag instead of filing an issue here: http://stackoverflow.com/questions/tagged/amp-html 10 | - If you have questions/issues related to Google Search please ask them in Google's AMP forum instead of filing an issue here: https://goo.gl/utQ1KZ 11 | 12 | Still here? Great! What's happening with rollup-plugin-closure-compiler? Delete everything except the headers (including this text). 13 | 14 | ## What's the issue? 15 | 16 | Briefly describe the bug/feature request. 17 | 18 | ## How do we reproduce the issue? 19 | 20 | We'll likely need to know: 21 | 1. Your Rollup configuration. 22 | 2. Error logs from your console when invoking Rollup with this plugin present. 23 | 3. Error logs when this plugin is removed from your Rollup configuration. 24 | 25 | If this is a feature request you can use this section to point to a prototype/mockup that will help us understand the request. 26 | 27 | ## Additional context 28 | 29 | Add any other context about the problem here. 30 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | 5 | --- 6 | 7 | **Please only file bugs/feature requests for rollup-plugin-closure-compiler here.** 8 | 9 | - If you have questions about how to use AMP or other general questions about AMP please ask them on Stack Overflow under the AMP HTML tag instead of filing an issue here: http://stackoverflow.com/questions/tagged/amp-html 10 | - If you have questions/issues related to Google Search please ask them in Google's AMP forum instead of filing an issue here: https://goo.gl/utQ1KZ 11 | 12 | Still here? Great! What do you think we can improve with rollup-plugin-closure-compiler? Delete everything except the headers (including this text). 13 | 14 | ## Is your feature request related to a problem? Please describe. 15 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 16 | 17 | ## Describe the solution you'd like 18 | A clear and concise description of what you want to happen. 19 | 20 | ## Describe alternatives you've considered 21 | A clear and concise description of any alternative solutions or features you've considered. 22 | 23 | ## Additional context 24 | 25 | Add any other context about the feature request here. 26 | -------------------------------------------------------------------------------- /.github/disable_workflows/codecoverage.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: [pull_request] 4 | 5 | jobs: 6 | build: 7 | strategy: 8 | matrix: 9 | platform: [ubuntu-latest] 10 | node-version: [12.x] 11 | runs-on: ${{ matrix.platform }} 12 | steps: 13 | - uses: actions/checkout@v1 14 | - name: Use Node.js ${{ matrix.node-version }} 15 | uses: actions/setup-node@v1 16 | with: 17 | node-version: ${{ matrix.node-version }} 18 | - run: yarn install 19 | - run: yarn pretest 20 | - run: yarn c8 ava 21 | - run: yarn c8 report --reporter=lcovonly 22 | - run: yarn codecov -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: [pull_request] 4 | 5 | jobs: 6 | build: 7 | strategy: 8 | matrix: 9 | platform: [ubuntu-latest, macos-latest] 10 | node-version: [12.x] 11 | runs-on: ${{ matrix.platform }} 12 | steps: 13 | - uses: actions/checkout@v1 14 | - name: Use Node.js ${{ matrix.node-version }} 15 | uses: actions/setup-node@v1 16 | with: 17 | node-version: ${{ matrix.node-version }} 18 | - run: yarn install 19 | - run: yarn test -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/* 2 | package-lock.json 3 | .vscode/* 4 | .DS_Store 5 | dist/ 6 | transpile/ 7 | transpile-tests/ 8 | coverage/* -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rollup-plugin-closure-compiler 2 | 3 | Leverage [Closure Compiler](https://developers.google.com/closure/compiler/) to minify and optimize JavaScript with [Rollup](https://rollupjs.org/guide/en). 4 | 5 | Generally Closure Compiler will produce superior minification than other projects, but historically has been more difficult to use. The goal of this plugin is to reduce this friction. 6 | 7 | ## Installation 8 | 9 | ```bash 10 | npm install @ampproject/rollup-plugin-closure-compiler --save-dev 11 | ``` 12 | 13 | ## Usage 14 | 15 | Invoke Closure Compiler from your Rollup configuration. 16 | 17 | ```js 18 | // rollup.config.js 19 | import compiler from '@ampproject/rollup-plugin-closure-compiler'; 20 | 21 | export default { 22 | input: 'main.js', 23 | output: { 24 | file: 'bundle.js', 25 | format: 'iife', 26 | }, 27 | plugins: [ 28 | compiler(), 29 | ], 30 | } 31 | ``` 32 | 33 | If you would like to provide additional [flags and options](https://github.com/google/closure-compiler/wiki/Flags-and-Options) to Closure Compiler, pass them via key-value pairs. 34 | 35 | ```js 36 | // rollup.config.js 37 | import compiler from '@ampproject/rollup-plugin-closure-compiler'; 38 | 39 | export default { 40 | input: 'main.js', 41 | output: { 42 | file: 'bundle.js', 43 | format: 'iife', 44 | }, 45 | plugins: [ 46 | compiler({ 47 | formatting: 'PRETTY_PRINT' 48 | }), 49 | ], 50 | } 51 | ``` 52 | 53 | ### Automatic Closure Configuration 54 | 55 | This plugin will modify the enable the `assume_function_wrapper` output option for Closure Compiler when `es` format is specifed to Rollup. **Note**: This is overrideable via passed flags and options. 56 | 57 | ```js 58 | // rollup.config.js 59 | import compiler from '@ampproject/rollup-plugin-closure-compiler'; 60 | 61 | export default { 62 | input: 'main.js', 63 | output: { 64 | file: 'bundle.js', 65 | format: 'es', 66 | }, 67 | plugins: [ 68 | compiler(), 69 | ], 70 | } 71 | ``` 72 | 73 | If your Rollup configuration outputs an IIFE format bundle with a specified name, this plugin will add an extern to ensure the name does not get mangled. **Note**: This is overrideable via passed flags and options. 74 | 75 | ```js 76 | // rollup.config.js 77 | import compiler from '@ampproject/rollup-plugin-closure-compiler'; 78 | 79 | export default { 80 | input: 'main.js', 81 | output: { 82 | file: 'bundle.js', 83 | format: 'iife', 84 | name: 'MyAwesomeThing' 85 | }, 86 | plugins: [ 87 | compiler(), 88 | ], 89 | } 90 | ``` 91 | 92 | ## Security disclosures 93 | 94 | The AMP Project accepts responsible security disclosures through the [Google Application Security program](https://www.google.com/about/appsecurity/). 95 | 96 | ## Code of conduct 97 | 98 | The AMP Project strives for a positive and growing project community that provides a safe environment for everyone. All members, committers and volunteers in the community are required to act according to the [code of conduct](.github/CODE_OF_CONDUCT.md). 99 | 100 | ## License 101 | 102 | rollup-plugin-closure-compiler is licensed under the [Apache License, Version 2.0](LICENSE). 103 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@ampproject/rollup-plugin-closure-compiler", 3 | "version": "0.27.0", 4 | "description": "Rollup + Google Closure Compiler", 5 | "main": "dist/index.js", 6 | "jsnext:main": "dist/index.mjs", 7 | "types": "./dist/index.d.ts", 8 | "files": [ 9 | "dist" 10 | ], 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/ampproject/rollup-plugin-closure-compiler.git" 14 | }, 15 | "author": "The AMP HTML Authors", 16 | "engines": { 17 | "node": ">=10" 18 | }, 19 | "keywords": [ 20 | "rollup-plugin" 21 | ], 22 | "license": "Apache-2.0", 23 | "scripts": { 24 | "pretest": "tsc -p tsconfig.test.json", 25 | "test": "ava", 26 | "precoverage": "yarn pretest && c8 ava", 27 | "coverage": "c8 report --reporter=html", 28 | "postcoverage": "sirv coverage/", 29 | "build": "rimraf dist transpile transpile-tests && tsc -p tsconfig.json & wait", 30 | "postbuild": "rollup -c", 31 | "release": "np --no-2fa --any-branch", 32 | "prepublishOnly": "npm-run-all build" 33 | }, 34 | "peerDependencies": { 35 | "rollup": ">=1.27" 36 | }, 37 | "dependencies": { 38 | "@ampproject/remapping": "0.2.0", 39 | "acorn": "7.3.1", 40 | "acorn-walk": "7.1.1", 41 | "estree-walker": "2.0.1", 42 | "google-closure-compiler": "20210808.0.0", 43 | "magic-string": "0.25.7", 44 | "uuid": "8.1.0" 45 | }, 46 | "devDependencies": { 47 | "@types/acorn": "4.0.5", 48 | "@types/estree": "0.0.44", 49 | "@types/node": "14.0.13", 50 | "@types/uuid": "8.0.0", 51 | "ava": "2.4.0", 52 | "builtins": "3.0.1", 53 | "c8": "7.2.0", 54 | "codecov": "3.7.0", 55 | "husky": "4.2.5", 56 | "lint-staged": "10.2.9", 57 | "np": "https://github.com/pixelastic/np/tarball/c3ab2e3b053c7da0ce40a572ca1616273ac080f8", 58 | "npm-run-all": "4.1.5", 59 | "prettier": "2.0.5", 60 | "rimraf": "3.0.2", 61 | "rollup": "2.15.0", 62 | "rollup-plugin-copy": "3.3.0", 63 | "sirv-cli": "1.0.0", 64 | "typescript": "3.9.5" 65 | }, 66 | "lint-staged": { 67 | "*.ts": [ 68 | "prettier --write" 69 | ], 70 | "*.test.js": [ 71 | "prettier --write" 72 | ] 73 | }, 74 | "husky": { 75 | "hooks": { 76 | "pre-push": "yarn npm-run-all test build", 77 | "pre-commit": "lint-staged" 78 | } 79 | }, 80 | "ava": { 81 | "files": [ 82 | "test/**/*.test.js" 83 | ], 84 | "verbose": true 85 | }, 86 | "prettier": { 87 | "printWidth": 120, 88 | "trailingComma": "all", 89 | "parser": "typescript", 90 | "singleQuote": true 91 | }, 92 | "volta": { 93 | "node": "16.6.1", 94 | "yarn": "1.22.4" 95 | }, 96 | "publishConfig": { 97 | "access": "public" 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:base" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import pkg from './package.json'; 18 | import builtins from 'builtins'; 19 | import copy from 'rollup-plugin-copy'; 20 | 21 | export default { 22 | input: './transpile/index.js', 23 | external: [ 24 | ...builtins(), 25 | ...Object.keys(pkg.dependencies || {}), 26 | ...Object.keys(pkg.peerDependencies || {}), 27 | ], 28 | output: [ 29 | { 30 | file: './dist/index.mjs', 31 | format: 'es', 32 | }, 33 | { 34 | file: './dist/index.js', 35 | format: 'cjs', 36 | }, 37 | ], 38 | plugins: [ 39 | copy({ 40 | targets: [ 41 | { src: 'transpile/**/*.d.ts', dest: 'dist' }, 42 | ], 43 | flatten: false, 44 | }), 45 | ], 46 | }; 47 | -------------------------------------------------------------------------------- /src/acorn.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { 18 | Program, 19 | BaseNode, 20 | Identifier, 21 | ImportDeclaration, 22 | VariableDeclarator, 23 | BlockStatement, 24 | ExportNamedDeclaration, 25 | ExportDefaultDeclaration, 26 | ExportAllDeclaration, 27 | FunctionDeclaration, 28 | VariableDeclaration, 29 | ClassDeclaration, 30 | ExportSpecifier, 31 | Property, 32 | } from 'estree'; 33 | import * as acorn from 'acorn'; 34 | import { log } from './debug'; 35 | import { writeTempFile } from './temp-file'; 36 | const acornWalk = require('acorn-walk'); 37 | 38 | export const walk = { 39 | simple: acornWalk.simple, 40 | ancestor: acornWalk.ancestor, 41 | }; 42 | 43 | const DEFAULT_ACORN_OPTIONS = { 44 | ecmaVersion: 2020 as any, 45 | sourceType: 'module' as any, 46 | preserveParens: false, 47 | ranges: true, 48 | }; 49 | 50 | export async function parse(fileName: string, source: string): Promise { 51 | try { 52 | return (acorn.parse(source, DEFAULT_ACORN_OPTIONS) as unknown) as Program; 53 | } catch (e) { 54 | log(`parse exception in ${fileName}`, `file://${await writeTempFile(source, '.js')}`); 55 | throw e; 56 | } 57 | } 58 | 59 | export function isIdentifier(node: BaseNode): node is Identifier { 60 | return node.type === 'Identifier'; 61 | } 62 | export function isImportDeclaration(node: BaseNode): node is ImportDeclaration { 63 | return node.type === 'ImportDeclaration'; 64 | } 65 | export function isImportExpression(node: BaseNode): boolean { 66 | // @types/estree does not yet support 2020 addons to ECMA. 67 | // This includes ImportExpression ... import("thing") 68 | return node.type === 'ImportExpression'; 69 | } 70 | export function isVariableDeclarator(node: BaseNode): node is VariableDeclarator { 71 | return node.type === 'VariableDeclarator'; 72 | } 73 | export function isBlockStatement(node: BaseNode): node is BlockStatement { 74 | return node.type === 'BlockStatement'; 75 | } 76 | export function isProgram(node: BaseNode): node is Program { 77 | return node.type === 'Program'; 78 | } 79 | export function isExportNamedDeclaration(node: BaseNode): node is ExportNamedDeclaration { 80 | return node.type === 'ExportNamedDeclaration'; 81 | } 82 | export function isExportDefaultDeclaration(node: BaseNode): node is ExportDefaultDeclaration { 83 | return node.type === 'ExportDefaultDeclaration'; 84 | } 85 | export function isExportAllDeclaration(node: BaseNode): node is ExportAllDeclaration { 86 | return node.type === 'ExportAllDeclaration'; 87 | } 88 | export function isFunctionDeclaration(node: BaseNode): node is FunctionDeclaration { 89 | return node.type === 'FunctionDeclaration'; 90 | } 91 | export function isVariableDeclaration(node: BaseNode): node is VariableDeclaration { 92 | return node.type === 'VariableDeclaration'; 93 | } 94 | export function isClassDeclaration(node: BaseNode): node is ClassDeclaration { 95 | return node.type === 'ClassDeclaration'; 96 | } 97 | export function isExportSpecifier(node: BaseNode): node is ExportSpecifier { 98 | return node.type === 'ExportSpecifier'; 99 | } 100 | export function isProperty(node: BaseNode): node is Property { 101 | return node.type === 'Property'; 102 | } 103 | -------------------------------------------------------------------------------- /src/debug.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { writeTempFile } from './temp-file'; 18 | 19 | const DEBUG_ENABLED = false; 20 | 21 | /* c8 ignore next 15 */ 22 | export async function logTransformChain( 23 | file: string, 24 | stage: string, 25 | messages: Array<[string, string]>, 26 | ): Promise { 27 | if (!DEBUG_ENABLED) return; 28 | let output: string = `\n${file} - ${stage}`; 29 | for (const [message, source] of messages) { 30 | output += `\n${message.substr(0, 15).padEnd(18, '.')} - file://${await writeTempFile( 31 | source, 32 | '.js', 33 | )}`; 34 | } 35 | console.log(output); 36 | } 37 | 38 | /* c8 ignore next 7 */ 39 | export const log = (preamble: string | undefined, message: string | object): void | null => { 40 | if (!DEBUG_ENABLED) return; 41 | if (preamble) { 42 | console.log(preamble); 43 | } 44 | console.log(message); 45 | }; 46 | -------------------------------------------------------------------------------- /src/google-closure-compiler.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // FORK of DefinatelyTyped definitions for `google-closure-compiler` 18 | 19 | // Type definitions for google-closure-compiler 20 | // Project: https://github.com/chadkillingsworth/closure-compiler-npm 21 | // Definitions by: Evan Martin 22 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped 23 | 24 | /// 25 | 26 | declare module 'google-closure-compiler' { 27 | import * as child_process from 'child_process'; 28 | 29 | // The "json_streams" compiler flag lets the compiler accept/produce 30 | // arrays of JSON objects in this shape for input/output. 31 | interface JSONStreamFile { 32 | path: string; 33 | src: string; 34 | srcmap?: string; // TODO(evan): pass through source maps. 35 | } 36 | 37 | interface Compiler { 38 | JAR_PATH: string | null; 39 | javaPath: string; 40 | logger: (...args: any[]) => void; 41 | spawnOptions: { [key: string]: string }; 42 | 43 | run( 44 | callback?: (exitCode: number, stdout: string, stderr: string) => void, 45 | ): child_process.ChildProcess; 46 | 47 | getFullCommand(): string; 48 | } 49 | 50 | type CompileOption = string | boolean; 51 | type CompileOptions = string[] | { [key: string]: CompileOption | CompileOption[] }; 52 | export const compiler: { 53 | new (opts: CompileOptions | string[], extraCommandArgs?: string[]): Compiler; 54 | 55 | JAR_PATH: string; 56 | COMPILER_PATH: string; 57 | CONTRIB_PATH: string; 58 | }; 59 | } 60 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { CompileOptions } from 'google-closure-compiler'; 18 | import { promises as fsPromises } from 'fs'; 19 | import { 20 | OutputOptions, 21 | Plugin, 22 | InputOptions, 23 | PluginContext, 24 | RenderedChunk, 25 | TransformResult, 26 | } from 'rollup'; 27 | import compiler from './compiler'; 28 | import options from './options'; 29 | import { 30 | transform as sourceTransform, 31 | create as createSourceTransforms, 32 | } from './transformers/source/transforms'; 33 | import { preCompilation, create as createChunkTransforms } from './transformers/chunk/transforms'; 34 | import { Mangle } from './transformers/mangle'; 35 | import { Ebbinghaus } from './transformers/ebbinghaus'; 36 | import { SourceTransform } from './transform'; 37 | 38 | export default function closureCompiler(requestedCompileOptions: CompileOptions = {}): Plugin { 39 | const mangler: Mangle = new Mangle(); 40 | const memory: Ebbinghaus = new Ebbinghaus(); 41 | let inputOptions: InputOptions; 42 | let context: PluginContext; 43 | let sourceTransforms: Array; 44 | 45 | return { 46 | name: 'closure-compiler', 47 | options: options => (inputOptions = options), 48 | buildStart() { 49 | context = this; 50 | sourceTransforms = createSourceTransforms( 51 | context, 52 | requestedCompileOptions, 53 | mangler, 54 | memory, 55 | inputOptions, 56 | {}, 57 | ); 58 | if ( 59 | 'compilation_level' in requestedCompileOptions && 60 | requestedCompileOptions.compilation_level === 'ADVANCED_OPTIMIZATIONS' && 61 | Array.isArray(inputOptions.input) 62 | ) { 63 | context.warn( 64 | 'Code Splitting with Closure Compiler ADVANCED_OPTIMIZATIONS is not currently supported.', 65 | ); 66 | } 67 | }, 68 | transform: async (code: string, id: string): Promise => { 69 | if (sourceTransforms.length > 0) { 70 | const output = await sourceTransform(code, id, sourceTransforms); 71 | return output || null; 72 | } 73 | return null; 74 | }, 75 | renderChunk: async (code: string, chunk: RenderedChunk, outputOptions: OutputOptions) => { 76 | mangler.debug(); 77 | 78 | const renderChunkTransforms = createChunkTransforms( 79 | context, 80 | requestedCompileOptions, 81 | mangler, 82 | memory, 83 | inputOptions, 84 | outputOptions, 85 | ); 86 | const preCompileOutput = (await preCompilation(code, chunk, renderChunkTransforms)).code; 87 | const [compileOptions, mapFile] = await options( 88 | requestedCompileOptions, 89 | outputOptions, 90 | preCompileOutput, 91 | renderChunkTransforms, 92 | ); 93 | 94 | try { 95 | return { 96 | code: await compiler(compileOptions, chunk, renderChunkTransforms), 97 | map: JSON.parse(await fsPromises.readFile(mapFile, 'utf8')), 98 | }; 99 | } catch (error) { 100 | throw error; 101 | } 102 | }, 103 | }; 104 | } 105 | -------------------------------------------------------------------------------- /src/parsing/import-specifiers.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { IMPORT_SPECIFIER, IMPORT_NAMESPACE_SPECIFIER, IMPORT_DEFAULT_SPECIFIER } from '../types'; 18 | import { ImportSpecifier, ImportDefaultSpecifier, ImportNamespaceSpecifier } from 'estree'; 19 | 20 | export interface Specifiers { 21 | default: string | null; 22 | specific: Array; 23 | local: Array; 24 | namespace: boolean; 25 | } 26 | 27 | export function Specifiers( 28 | specifiers: Array, 29 | ): Specifiers { 30 | const returnable: Specifiers = { 31 | default: null, 32 | specific: [], 33 | local: [], 34 | namespace: false, 35 | }; 36 | 37 | for (const specifier of specifiers) { 38 | returnable.local.push(specifier.local.name); 39 | 40 | switch (specifier.type) { 41 | case IMPORT_SPECIFIER: 42 | const { name: local } = (specifier as ImportSpecifier).local; 43 | const { name: imported } = (specifier as ImportSpecifier)?.imported || { 44 | name: specifier.local, 45 | }; 46 | 47 | if (local === imported) { 48 | returnable.specific.push(local); 49 | } else { 50 | returnable.specific.push(`${imported} as ${local}`); 51 | } 52 | break; 53 | case IMPORT_NAMESPACE_SPECIFIER: 54 | const { name: namespace } = specifier.local; 55 | returnable.specific.push(namespace); 56 | returnable.namespace = true; 57 | break; 58 | case IMPORT_DEFAULT_SPECIFIER: 59 | returnable.default = specifier.local.name; 60 | break; 61 | } 62 | } 63 | 64 | return returnable; 65 | } 66 | 67 | export function FormatSpecifiers(specifiers: Specifiers, name: string): string { 68 | const hasDefault = specifiers.default !== null; 69 | const hasNamespace = specifiers.namespace === true; 70 | const hasSpecifics = !hasNamespace && specifiers.specific.length > 0; 71 | const hasLocals = specifiers.local.length > 0; 72 | const includesFrom = hasNamespace || hasNamespace || hasSpecifics || hasLocals; 73 | let formatted: string = 'import'; 74 | let values: Array = []; 75 | 76 | if (hasDefault) { 77 | values.push(`${specifiers.default}`); 78 | } 79 | if (hasNamespace) { 80 | values.push(`* as ${specifiers.specific[0]}`); 81 | } 82 | if (hasSpecifics) { 83 | values.push(`{${specifiers.specific.join(',')}}`); 84 | } 85 | formatted += `${hasDefault || hasNamespace ? ' ' : ''}${values.join(',')}${ 86 | hasSpecifics ? '' : ' ' 87 | }${includesFrom ? 'from' : ''}'${name}';`; 88 | 89 | return formatted; 90 | } 91 | -------------------------------------------------------------------------------- /src/parsing/literal-name.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { Literal, SimpleLiteral } from 'estree'; 18 | 19 | export function literalName(literal: Literal): string { 20 | return (literal as SimpleLiteral).value as string; 21 | } 22 | -------------------------------------------------------------------------------- /src/parsing/preserve-default-export.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { ExpressionStatement, AssignmentExpression } from 'estree'; 18 | import { ExportDetails, Range } from '../types'; 19 | import MagicString from 'magic-string'; 20 | 21 | export function PreserveDefault( 22 | code: string, 23 | source: MagicString, 24 | ancestor: ExpressionStatement, 25 | exportDetails: ExportDetails, 26 | exportInline: boolean, 27 | ): boolean { 28 | const assignmentExpression = ancestor.expression as AssignmentExpression; 29 | const [leftStart]: Range = assignmentExpression.left.range as Range; 30 | const [rightStart]: Range = assignmentExpression.right.range as Range; 31 | 32 | source.overwrite(leftStart, rightStart, 'export default '); 33 | 34 | return false; 35 | } 36 | -------------------------------------------------------------------------------- /src/source-map.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import MagicString from 'magic-string'; 18 | import remapping from '@ampproject/remapping'; 19 | import SourceMap from '@ampproject/remapping/dist/types/source-map'; 20 | import { DecodedSourceMap as RemappingDecodedSourceMap } from '@ampproject/remapping/dist/types/types'; 21 | import { ExistingRawSourceMap } from 'rollup'; 22 | 23 | export function createDecodedSourceMap( 24 | magicstring: MagicString, 25 | source: string, 26 | ): RemappingDecodedSourceMap { 27 | return { 28 | ...magicstring.generateDecodedMap({ hires: true, source }), 29 | version: 3, 30 | }; 31 | } 32 | 33 | export function createExistingRawSourceMap( 34 | maps: Array, 35 | file: string, 36 | ): ExistingRawSourceMap { 37 | const remappedSourceMap: SourceMap = remapping(maps, () => null); 38 | 39 | return { 40 | ...remappedSourceMap, 41 | sources: remappedSourceMap.sources.map(source => source || ''), 42 | sourcesContent: remappedSourceMap.sourcesContent?.map(content => content || '') || undefined, 43 | file, 44 | }; 45 | } 46 | -------------------------------------------------------------------------------- /src/temp-file.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import * as path from 'path'; 18 | import { tmpdir } from 'os'; 19 | import { promises } from 'fs'; 20 | import * as crypto from 'crypto'; 21 | import { v4 } from 'uuid'; 22 | 23 | export async function writeTempFile( 24 | content: string, 25 | extension: string = '', 26 | stableName: boolean = true, 27 | ): Promise { 28 | let hash: string; 29 | 30 | if (stableName) { 31 | hash = crypto 32 | .createHash('sha1') 33 | .update(content) 34 | .digest('hex'); 35 | } else { 36 | hash = v4(); 37 | } 38 | const fullpath: string = path.join(tmpdir(), hash + extension); 39 | await promises.mkdir(path.dirname(fullpath), { recursive: true }); 40 | await promises.writeFile(fullpath, content, 'utf-8'); 41 | 42 | return fullpath; 43 | } 44 | -------------------------------------------------------------------------------- /src/transformers/chunk/asi.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { ChunkTransform } from '../../transform'; 18 | import { Range } from '../../types'; 19 | import { parse } from '../../acorn'; 20 | import MagicString from 'magic-string'; 21 | 22 | export default class ASITransform extends ChunkTransform { 23 | public name = 'ASITransform'; 24 | 25 | /** 26 | * Small reduction in semi-colons, removing from end of block statements. 27 | * @param source source following closure compiler minification 28 | */ 29 | public async post(fileName: string, source: MagicString): Promise { 30 | const code = source.toString(); 31 | const program = await parse(fileName, code); 32 | 33 | if (program.body) { 34 | const lastStatement = program.body[program.body.length - 1]; 35 | if (lastStatement) { 36 | const [start, end] = lastStatement.range as Range; 37 | if (lastStatement.type === 'EmptyStatement') { 38 | source.remove(start, end); 39 | } else { 40 | const lastStatementSource = code.substring(start, end); 41 | if (lastStatementSource.endsWith(';')) { 42 | source.overwrite(start, end, code.substring(start, end - 1)); 43 | } 44 | } 45 | } 46 | } 47 | 48 | return source; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/transformers/chunk/cjs.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { ChunkTransform } from '../../transform'; 18 | import { OutputOptions } from 'rollup'; 19 | 20 | const HEADER = `/** 21 | * @fileoverview Externs built via derived configuration from Rollup or input code. 22 | * This extern contains the cjs typing info for modules. 23 | * @externs 24 | */ 25 | 26 | /** 27 | * @typedef {{ 28 | * __esModule: boolean, 29 | * }} 30 | */ 31 | var exports;`; 32 | 33 | /** 34 | * This Transform will apply only if the Rollup configuration is for a cjs output. 35 | * 36 | * In order to preserve the __esModules boolean on an Object, this typedef needs to be present. 37 | */ 38 | export default class CJSTransform extends ChunkTransform { 39 | public name = 'CJSTransform'; 40 | 41 | public extern(options: OutputOptions): string | null { 42 | if (options.format === 'cjs') { 43 | return HEADER; 44 | } 45 | 46 | return null; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/transformers/chunk/const.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { ChunkTransform } from '../../transform'; 18 | import { Range } from '../../types'; 19 | import { parse, walk } from '../../acorn'; 20 | import { VariableDeclaration } from 'estree'; 21 | import MagicString from 'magic-string'; 22 | 23 | export default class ConstTransform extends ChunkTransform { 24 | public name = 'ConstTransform'; 25 | 26 | /** 27 | * When outputting ES2017+ code there is neglagible differences between `const` and `let` for runtime performance. 28 | * So, we replace all usages of `const` with `let` to enable more variable folding. 29 | * @param code source following closure compiler minification 30 | * @return code after removing the strict mode declaration (when safe to do so) 31 | */ 32 | public async pre(fileName: string, source: MagicString): Promise { 33 | const code = source.toString(); 34 | const program = await parse(fileName, code); 35 | 36 | walk.simple(program, { 37 | VariableDeclaration(node: VariableDeclaration) { 38 | const [start, end]: Range = node.range as Range; 39 | if (node.kind === 'const') { 40 | source.overwrite(start, end, code.substring(start, end).replace('const', 'let')); 41 | } 42 | }, 43 | }); 44 | 45 | return source; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/transformers/chunk/hashbang-apply.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { ChunkTransform } from '../../transform'; 18 | import { TransformInterface } from '../../types'; 19 | import MagicString from 'magic-string'; 20 | 21 | /** 22 | * Closure Compiler will not compile code that is prefixed with a hashbang (common to rollup output for CLIs). 23 | * 24 | * This transform will restore the hashbang if Ebbinghaus knows it exists. 25 | */ 26 | export default class HashbangApplyTransform extends ChunkTransform implements TransformInterface { 27 | public name = 'HashbangApplyTransform'; 28 | 29 | /** 30 | * @param source MagicString of source to process post Closure Compilation. 31 | */ 32 | public async post(fileName: string, source: MagicString): Promise { 33 | if (this.memory.hashbang === null) { 34 | return source; 35 | } 36 | 37 | source.prepend(this.memory.hashbang + '\n'); 38 | return source; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/transformers/chunk/hashbang-remove.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { ChunkTransform } from '../../transform'; 18 | import { TransformInterface } from '../../types'; 19 | import MagicString from 'magic-string'; 20 | 21 | /** 22 | * Closure Compiler will not compile code that is prefixed with a hashbang (common to rollup output for CLIs). 23 | * 24 | * This transform will remove the hashbang (if present) and ask Ebbinghaus to remember if for after compilation. 25 | */ 26 | export default class HashbangRemoveTransform extends ChunkTransform implements TransformInterface { 27 | public name = 'HashbangRemoveTransform'; 28 | 29 | /** 30 | * @param source MagicString of source to process post Closure Compilation. 31 | */ 32 | public async pre(fileName: string, source: MagicString): Promise { 33 | const stringified = source.trim().toString(); 34 | const match = /^#!.*/.exec(stringified); 35 | 36 | if (!match) { 37 | return source; 38 | } 39 | 40 | this.memory.hashbang = match[0]; 41 | source.remove(0, match[0].length); 42 | return source; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/transformers/chunk/iife.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { ChunkTransform } from '../../transform'; 18 | import { OutputOptions } from 'rollup'; 19 | 20 | const HEADER = `/** 21 | * @fileoverview Externs built via derived configuration from Rollup or input code. 22 | * This extern contains the iife name so it does not get mangled at the top level. 23 | * @externs 24 | */ 25 | `; 26 | 27 | /** 28 | * This Transform will apply only if the Rollup configuration is for a iife output with a defined name. 29 | * 30 | * In order to preserve the name of the iife output, derive an extern definition for Closure Compiler. 31 | * This preserves the name after compilation since Closure now believes it to be a well known global. 32 | */ 33 | export default class IifeTransform extends ChunkTransform { 34 | public name = 'IifeTransform'; 35 | 36 | public extern(options: OutputOptions): string | null { 37 | if (options.format === 'iife' && options.name) { 38 | return HEADER + `window['${options.name}'] = ${options.name};\n`; 39 | } 40 | 41 | return null; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/transformers/chunk/literal-computed-keys.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { ChunkTransform } from '../../transform'; 18 | import { Range, TransformInterface } from '../../types'; 19 | import MagicString from 'magic-string'; 20 | import { ObjectExpression } from 'estree'; 21 | import { parse, walk, isProperty } from '../../acorn'; 22 | 23 | /** 24 | * Closure Compiler will not transform computed keys with literal values back to the literal value. 25 | * e.g {[0]: 'value'} => {0: 'value'} 26 | * 27 | * This transform does so only if a computed key is a Literal, and thus easily known to be static. 28 | * @see https://astexplorer.net/#/gist/d2414b45a81db3a41ee6902bfd09947a/d7176ac33a2733e1a4b1f65ec3ac626e24f7b60d 29 | */ 30 | export default class LiteralComputedKeys extends ChunkTransform implements TransformInterface { 31 | public name = 'LiteralComputedKeysTransform'; 32 | 33 | /** 34 | * @param code source to parse, and modify 35 | * @return modified input source with computed literal keys 36 | */ 37 | public async post(fileName: string, source: MagicString): Promise { 38 | const program = await parse(fileName, source.toString()); 39 | 40 | walk.simple(program, { 41 | ObjectExpression(node: ObjectExpression) { 42 | for (const property of node.properties) { 43 | if (isProperty(property) && property.computed && property.key.type === 'Literal') { 44 | const [propertyStart]: Range = property.range as Range; 45 | const [valueStart]: Range = property.value.range as Range; 46 | 47 | source.overwrite( 48 | propertyStart, 49 | valueStart, 50 | `${property.key.value}${property.value.type !== 'FunctionExpression' ? ':' : ''}`, 51 | ); 52 | } 53 | } 54 | }, 55 | }); 56 | 57 | return source; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/transformers/chunk/strict.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { ChunkTransform } from '../../transform'; 18 | import { Range, TransformInterface, PluginOptions } from '../../types'; 19 | import { isESMFormat } from '../../options'; 20 | import MagicString from 'magic-string'; 21 | import { walk, parse } from '../../acorn'; 22 | import { ExpressionStatement, SimpleLiteral } from 'estree'; 23 | import { extname } from 'path'; 24 | import { OutputOptions } from 'rollup'; 25 | 26 | /** 27 | * Determines if Strict Mode should be removed from output. 28 | * @param pluginOptions 29 | * @param outputOptions 30 | * @param path 31 | */ 32 | function shouldRemoveStrictModeDeclarations( 33 | pluginOptions: PluginOptions, 34 | outputOptions: OutputOptions, 35 | path: string | undefined, 36 | ): boolean { 37 | if ('remove_strict_directive' in pluginOptions) { 38 | const removeDirective = pluginOptions['remove_strict_directive']; 39 | return removeDirective === undefined || removeDirective === true; 40 | } 41 | 42 | const isESMOutput: boolean = !!(path && extname(path) === '.mjs'); 43 | return isESMFormat(outputOptions) || isESMOutput; 44 | } 45 | 46 | export default class StrictTransform extends ChunkTransform implements TransformInterface { 47 | public name = 'StrictTransform'; 48 | 49 | /** 50 | * When outputting an es module, runtimes automatically apply strict mode conventions. 51 | * This means we can safely strip the 'use strict'; declaration from the top of the file. 52 | * @param code source following closure compiler minification 53 | * @return code after removing the strict mode declaration (when safe to do so) 54 | */ 55 | public async post(fileName: string, source: MagicString): Promise { 56 | const { file } = this.outputOptions; 57 | 58 | if (shouldRemoveStrictModeDeclarations(this.pluginOptions, this.outputOptions, file)) { 59 | const program = await parse(fileName, source.toString()); 60 | 61 | walk.simple(program, { 62 | ExpressionStatement(node: ExpressionStatement) { 63 | const { type, value } = node.expression as SimpleLiteral; 64 | const range: Range = node.range as Range; 65 | 66 | if (type === 'Literal' && value === 'use strict') { 67 | source.remove(...range); 68 | } 69 | }, 70 | }); 71 | 72 | return source; 73 | } 74 | 75 | return source; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/transformers/ebbinghaus.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Hermann Ebbinghaus is credited with discovering the forgetting curve. 19 | * 20 | * This class stores data the compiler would typically loose to the forgetting curve. 21 | * For instance: 22 | * - original source contained a `hashbang` 23 | * - original source used external imports 24 | * 25 | * This data can be used later to inform transforms following Closure Compiler. 26 | * 27 | * For more information, visit: https://en.wikipedia.org/wiki/Hermann_Ebbinghaus 28 | */ 29 | 30 | export class Ebbinghaus { 31 | public hashbang: string | null = null; 32 | } 33 | -------------------------------------------------------------------------------- /src/transformers/source/exports.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { SourceTransform } from '../../transform'; 18 | import MagicString from 'magic-string'; 19 | import { parse, isExportNamedDeclaration, isExportDefaultDeclaration, isExportAllDeclaration } from '../../acorn'; 20 | import { asyncWalk as estreeWalk } from 'estree-walker'; 21 | import { ExportDetails } from '../../types'; 22 | import { BaseNode } from 'estree'; 23 | import { NamedDeclaration, DefaultDeclaration } from '../../parsing/export-details'; 24 | 25 | /** 26 | * Notes for Kris 27 | * 28 | * Left off here with a few questions. 29 | * 1. How do we know the source to use for export mangling, the current file could be imported with many paths. 30 | * - Can rollup tell us somehow? 31 | * 2. 32 | */ 33 | 34 | export class ExportTransform extends SourceTransform { 35 | public name: string = 'ExportTransform'; 36 | 37 | public transform = async (id: string, source: MagicString): Promise => { 38 | const program = await parse(id, source.toString()); 39 | 40 | // This will need to be two-pass. 41 | // 1. Find all exports, and mangle their names. 42 | // 2. Mangle all internal references 43 | let exportDetails: Array = []; 44 | await estreeWalk(program, { 45 | enter: async function(node: BaseNode) { 46 | if (isExportNamedDeclaration(node)) { 47 | exportDetails.push(...NamedDeclaration(node)); 48 | } else if (isExportDefaultDeclaration(node)) { 49 | exportDetails.push(...DefaultDeclaration(node)); 50 | } else if (isExportAllDeclaration(node)) { 51 | // TODO 52 | exportDetails.push(...[]); 53 | } 54 | }, 55 | }); 56 | 57 | for (const details of exportDetails) { 58 | const sourceId = this.mangler.sourceId(details.source || id); 59 | this.mangler.mangle(details.exported, sourceId); 60 | this.mangler.mangle(details.local, sourceId); 61 | } 62 | 63 | await this.mangler.execute(source, program); 64 | 65 | return source; 66 | }; 67 | } 68 | -------------------------------------------------------------------------------- /src/transformers/source/hashbang.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { SourceTransform } from '../../transform'; 18 | import { TransformInterface } from '../../types'; 19 | import MagicString from 'magic-string'; 20 | 21 | /** 22 | * Closure Compiler will not compile code that is prefixed with a hashbang (common to rollup output for CLIs). 23 | * 24 | * This transform will remove the hashbang (if present) and ask Ebbinghaus to remember if for after compilation. 25 | */ 26 | export default class HashbangTransform extends SourceTransform implements TransformInterface { 27 | public name = 'HashbangTransform'; 28 | 29 | public transform = async (id: string, source: MagicString): Promise => { 30 | const stringified = source.trim().toString(); 31 | const match = /^#!.*/.exec(stringified); 32 | 33 | if (!match) { 34 | return source; 35 | } 36 | 37 | this.memory.hashbang = match[0]; 38 | source.remove(0, match[0].length); 39 | return source; 40 | }; 41 | } 42 | -------------------------------------------------------------------------------- /src/transformers/source/imports.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { SourceTransform } from '../../transform'; 18 | import MagicString from 'magic-string'; 19 | import { parse, isImportDeclaration } from '../../acorn'; 20 | import { asyncWalk as walk } from 'estree-walker'; 21 | import { literalName } from '../../parsing/literal-name'; 22 | import { Specifiers } from '../../parsing/import-specifiers'; 23 | import { ImportDeclaration } from 'estree'; 24 | 25 | export class ImportTransform extends SourceTransform { 26 | public name: string = 'ImportTransform'; 27 | 28 | private mangle = async (node: ImportDeclaration, id: string) => { 29 | const name = literalName(node.source); 30 | const sourceId = this.mangler.sourceId((await this.context.resolve(name, id))?.id || name); 31 | const specifiers = Specifiers(node.specifiers); 32 | 33 | if (specifiers.default !== null) { 34 | this.mangler.mangle(specifiers.default, sourceId); 35 | } 36 | for (const specifier of specifiers.specific) { 37 | if (specifier.includes(' as ')) { 38 | const split = specifier.split(' as '); 39 | this.mangler.mangle(split[0], sourceId); 40 | this.mangler.mangle(split[1], sourceId); 41 | } else { 42 | this.mangler.mangle(specifier, sourceId); 43 | } 44 | } 45 | for (const specifier of specifiers.local) { 46 | this.mangler.mangle(specifier, sourceId); 47 | } 48 | }; 49 | 50 | public async transform(id: string, source: MagicString): Promise { 51 | const program = await parse(id, source.toString()); 52 | const { mangle } = this; 53 | 54 | // This is a two-part walk 55 | // 1. Identify all imports and rename them to indicate where they come from. 56 | // 2. Find usages of those imports and rename them. 57 | await walk(program, { 58 | enter: async function(node) { 59 | if (isImportDeclaration(node)) { 60 | await mangle(node, id); 61 | } 62 | }, 63 | }); 64 | 65 | this.mangler.execute(source, program); 66 | 67 | return source; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/transformers/source/transforms.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { SourceTransform, sourceLifecycle } from '../../transform'; 18 | import { Mangle } from '../mangle'; 19 | import { PluginContext, InputOptions, OutputOptions, SourceDescription } from 'rollup'; 20 | import { CompileOptions } from 'google-closure-compiler'; 21 | import HashbangTransform from './hashbang'; 22 | import { Ebbinghaus } from '../ebbinghaus'; 23 | 24 | const TRANSFORMS: Array = [HashbangTransform]; 25 | // Temporarily disabling many SourceTransforms, aligning for future release. 26 | // ImportTransform, ExportTransform 27 | 28 | /** 29 | * Instantiate transform class instances for the plugin invocation. 30 | * @param context Plugin context to bind for each transform instance. 31 | * @param requestedCompileOptions Originally requested compile options from configuration. 32 | * @param mangler Mangle instance used for this transform instance. 33 | * @param memory Ebbinghaus instance used to store information that could be lost from source. 34 | * @param inputOptions Rollup input options 35 | * @param outputOptions Rollup output options 36 | * @return Instantiated transform class instances for the given entry point. 37 | */ 38 | export const create = ( 39 | context: PluginContext, 40 | requestedCompileOptions: CompileOptions, 41 | mangler: Mangle, 42 | memory: Ebbinghaus, 43 | inputOptions: InputOptions, 44 | outputOptions: OutputOptions, 45 | ): Array => 46 | TRANSFORMS.map(transform => new transform(context, {}, mangler, memory, inputOptions, outputOptions)); 47 | 48 | /** 49 | * Run each transform's `transform` lifecycle. 50 | * @param code 51 | * @param transforms 52 | * @return source code following `transform` 53 | */ 54 | export async function transform( 55 | source: string, 56 | id: string, 57 | transforms: Array, 58 | ): Promise { 59 | return await sourceLifecycle(id, 'Transform', source, transforms); 60 | } 61 | -------------------------------------------------------------------------------- /src/types.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import MagicString from 'magic-string'; 18 | 19 | // @see https://github.com/estree/estree/blob/master/es2015.md#imports 20 | export const IMPORT_DECLARATION = 'ImportDeclaration'; 21 | export const IMPORT_SPECIFIER = 'ImportSpecifier'; 22 | export const IMPORT_DEFAULT_SPECIFIER = 'ImportDefaultSpecifier'; 23 | export const IMPORT_NAMESPACE_SPECIFIER = 'ImportNamespaceSpecifier'; 24 | 25 | // @see https://github.com/estree/estree/blob/master/es2015.md#exports 26 | export const EXPORT_NAMED_DECLARATION = 'ExportNamedDeclaration'; 27 | export const EXPORT_SPECIFIER = 'ExportSpecifier'; 28 | export const EXPORT_DEFAULT_DECLARATION = 'ExportDefaultDeclaration'; 29 | export const EXPORT_ALL_DECLARATION = 'ExportAllDeclaration'; 30 | export const ALL_EXPORT_DECLARATIONS = [ 31 | EXPORT_NAMED_DECLARATION, 32 | EXPORT_DEFAULT_DECLARATION, 33 | EXPORT_ALL_DECLARATION, 34 | ]; 35 | 36 | export type Range = [number, number]; 37 | 38 | export type CollectedExports = Map>; 39 | 40 | export enum ExportClosureMapping { 41 | NAMED_FUNCTION = 0, 42 | NAMED_CLASS = 1, 43 | NAMED_DEFAULT_FUNCTION = 2, 44 | DEFAULT_FUNCTION = 3, 45 | NAMED_DEFAULT_CLASS = 4, 46 | DEFAULT_CLASS = 5, 47 | NAMED_CONSTANT = 6, 48 | DEFAULT = 7, 49 | DEFAULT_VALUE = 8, 50 | DEFAULT_OBJECT = 9, 51 | } 52 | 53 | export interface ExportDetails { 54 | local: string; 55 | exported: string; 56 | type: ExportClosureMapping; 57 | range: Range; 58 | source: string | null; 59 | } 60 | 61 | export type TransformMethod = (code: string) => Promise; 62 | export interface TransformInterface { 63 | name: string; 64 | } 65 | 66 | export interface PluginOptions { 67 | [key: string]: string | boolean; 68 | } 69 | -------------------------------------------------------------------------------- /test/arrow-function/fixtures/multiple-arguments.esm.advanced.js: -------------------------------------------------------------------------------- 1 | export var multipleArguments=(a,b)=>console.log(a,b) 2 | -------------------------------------------------------------------------------- /test/arrow-function/fixtures/multiple-arguments.esm.default.js: -------------------------------------------------------------------------------- 1 | export var multipleArguments=(a,b)=>console.log(a,b) 2 | -------------------------------------------------------------------------------- /test/arrow-function/fixtures/multiple-arguments.esm.es5.js: -------------------------------------------------------------------------------- 1 | export function multipleArguments(a,b){return console.log(a,b)} 2 | -------------------------------------------------------------------------------- /test/arrow-function/fixtures/multiple-arguments.esm.pretty.js: -------------------------------------------------------------------------------- 1 | 2 | export var multipleArguments=(a, b) => console.log(a, b) 3 | -------------------------------------------------------------------------------- /test/arrow-function/fixtures/multiple-arguments.js: -------------------------------------------------------------------------------- 1 | export const multipleArguments = (ar, ar2) => console.log(ar, ar2); 2 | -------------------------------------------------------------------------------- /test/arrow-function/fixtures/single-argument.esm.advanced.js: -------------------------------------------------------------------------------- 1 | export var singleArgument=a=>console.log(a) 2 | -------------------------------------------------------------------------------- /test/arrow-function/fixtures/single-argument.esm.default.js: -------------------------------------------------------------------------------- 1 | export var singleArgument=a=>console.log(a) 2 | -------------------------------------------------------------------------------- /test/arrow-function/fixtures/single-argument.esm.es5.js: -------------------------------------------------------------------------------- 1 | export function singleArgument(a){return console.log(a)} 2 | -------------------------------------------------------------------------------- /test/arrow-function/fixtures/single-argument.esm.pretty.js: -------------------------------------------------------------------------------- 1 | 2 | export var singleArgument=a => console.log(a) 3 | -------------------------------------------------------------------------------- /test/arrow-function/fixtures/single-argument.js: -------------------------------------------------------------------------------- 1 | export const singleArgument = (ar) => console.log(ar); -------------------------------------------------------------------------------- /test/arrow-function/multiple-arguments.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2019 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('arrow-function', 'multiple-arguments'); -------------------------------------------------------------------------------- /test/arrow-function/single-argument.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2019 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('arrow-function', 'single-argument'); -------------------------------------------------------------------------------- /test/closure-config/fixtures/externs.js: -------------------------------------------------------------------------------- 1 | /** @externs */ 2 | var x = ''; -------------------------------------------------------------------------------- /test/closure-config/fixtures/prefer-config.esm.javascript.js: -------------------------------------------------------------------------------- 1 | console.log("foo") 2 | -------------------------------------------------------------------------------- /test/closure-config/fixtures/prefer-config.js: -------------------------------------------------------------------------------- 1 | console.log('foo'); -------------------------------------------------------------------------------- /test/closure-config/prefer-config.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2019 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import test from 'ava'; 18 | import options from '../../transpile-tests/options'; 19 | import { generator } from '../generator'; 20 | 21 | test('platform unspecified is respected', async t => { 22 | const typical = await options({}, {}, 'let x = 1;', []); 23 | 24 | t.is(typical[0].platform, undefined); 25 | }); 26 | 27 | test('platform javascript is respected', async t => { 28 | const javascriptPlatform = await options( 29 | { 30 | platform: 'javascript', 31 | }, 32 | {}, 33 | 'let x = 1;', 34 | [], 35 | ); 36 | 37 | t.is(javascriptPlatform[0].platform, 'javascript'); 38 | }); 39 | 40 | generator('closure-config', 'prefer-config', undefined, undefined, { 41 | javascript: { 42 | platform: 'javascript', 43 | }, 44 | }); 45 | -------------------------------------------------------------------------------- /test/closure-config/rollup-config-externs.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import test from 'ava'; 18 | import compile from '../../transpile-tests/options'; 19 | import path from 'path'; 20 | import {promises as fsPromises} from 'fs'; 21 | 22 | const PROVIDED_EXTERN = path.resolve('test', 'closure-config', 'fixtures', 'externs.js'); 23 | const IIFE_TRANSFORM_EXTERN_CONTENT = '/** @externs */ function wrapper(){}'; 24 | 25 | const IifeTransform = class { 26 | // Transforms have a public method `extern` that generates an extern 27 | // if one is needed for the transform. 28 | 29 | // This test ensures the externs created by transforms are passed to 30 | // closure compiler when the caller also passes externs. 31 | extern() { 32 | return IIFE_TRANSFORM_EXTERN_CONTENT; 33 | } 34 | }; 35 | 36 | test('when rollup configuration specifies externs, extern is leveraged', async t => { 37 | t.plan(3); 38 | 39 | const compiled = await compile({ 40 | externs: PROVIDED_EXTERN, 41 | }, { 42 | format: 'iife', 43 | name: 'wrapper', 44 | }, 'var x = 1;', [new IifeTransform()]); 45 | const externs = compiled[0].externs; 46 | 47 | t.is(externs.length, 2); 48 | t.true(externs.includes(PROVIDED_EXTERN)); 49 | 50 | // While we can use the path for the provided extern, we need to inspect the content of 51 | // the other extern to ensure it is the generated extern. 52 | // Externs are passed as filepaths to Closure Compiler. 53 | const fileContent = await fsPromises.readFile(externs.filter(path => path !== PROVIDED_EXTERN)[0], 'utf8'); 54 | t.true(fileContent === IIFE_TRANSFORM_EXTERN_CONTENT); 55 | }); 56 | -------------------------------------------------------------------------------- /test/closure-config/rollup-config-to-flags.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import test from 'ava'; 18 | import { defaults } from '../../transpile-tests/options'; 19 | 20 | test.beforeEach(async t => { 21 | t.context = { 22 | default: await defaults({}, [], null), 23 | esOutput: await defaults({ 24 | format: 'es', 25 | }, [], null), 26 | }; 27 | }); 28 | 29 | test('with no rollup configuration, language out is NO_TRANSPILE', t => { 30 | t.is(t.context.default.language_out, 'NO_TRANSPILE'); 31 | }); 32 | 33 | test('with no rollup configuration, assume_function_wrapper is false', t => { 34 | t.is(t.context.default.assume_function_wrapper, false); 35 | }); 36 | 37 | test('with no rollup configuration, warning_level is QUIET', t => { 38 | t.is(t.context.default.warning_level, 'QUIET'); 39 | }); 40 | 41 | test('with no rollup configuration, module_resolution is NODE', t => { 42 | t.is(t.context.default.module_resolution, 'NODE'); 43 | }); 44 | 45 | test('when rollup configuration specifies format es, assume_function_wrapper is true', t => { 46 | t.is(t.context.esOutput.assume_function_wrapper, true); 47 | }); 48 | -------------------------------------------------------------------------------- /test/closure-config/warning-level.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import test from 'ava'; 18 | import compile, {ERROR_WARNINGS_ENABLED_LANGUAGE_OUT_UNSPECIFIED, ERROR_WARNINGS_ENABLED_LANGUAGE_OUT_INVALID} from '../../transpile-tests/options'; 19 | 20 | test('with no language out set, and warnings set to verbose... an error is returned', async t => { 21 | try { 22 | await compile({ 23 | warning_level: 'VERBOSE', 24 | }, { 25 | format: 'es', 26 | }, 'var x = 1;', []); 27 | 28 | t.fail('compile completed without throwing an error.'); 29 | } catch (e) { 30 | t.is(e.message, ERROR_WARNINGS_ENABLED_LANGUAGE_OUT_UNSPECIFIED); 31 | } 32 | }); 33 | 34 | test('with language out set to no_transpile, and warnings set to verbose... an error is returned', async t => { 35 | try { 36 | await compile({ 37 | warning_level: 'VERBOSE', 38 | language_out: 'NO_TRANSPILE', 39 | }, { 40 | format: 'es', 41 | }, 'var x = 1;', []); 42 | 43 | t.fail('compile completed without throwing an error.'); 44 | } catch (e) { 45 | t.is(e.message, ERROR_WARNINGS_ENABLED_LANGUAGE_OUT_INVALID); 46 | } 47 | }); 48 | -------------------------------------------------------------------------------- /test/const-rename/fixtures/rename.esm.advanced.js: -------------------------------------------------------------------------------- 1 | let b=[3,4],c=[5,6];export function yes(a){return 0<=c.indexOf(a)&&0<=b.indexOf(a)} 2 | -------------------------------------------------------------------------------- /test/const-rename/fixtures/rename.esm.default.js: -------------------------------------------------------------------------------- 1 | let b=[3,4],c=[5,6];export function yes(a){return 0<=c.indexOf(a)&&0<=b.indexOf(a)} 2 | -------------------------------------------------------------------------------- /test/const-rename/fixtures/rename.esm.es5.js: -------------------------------------------------------------------------------- 1 | var b=[3,4],c=[5,6];export function yes(a){return 0<=c.indexOf(a)&&0<=b.indexOf(a)} 2 | -------------------------------------------------------------------------------- /test/const-rename/fixtures/rename.esm.pretty.js: -------------------------------------------------------------------------------- 1 | 2 | let b = [3, 4], c = [5, 6]; 3 | export function yes(a) { 4 | return 0 <= c.indexOf(a) && 0 <= b.indexOf(a); 5 | } 6 | -------------------------------------------------------------------------------- /test/const-rename/fixtures/rename.js: -------------------------------------------------------------------------------- 1 | const ALLOWED_TYPES = [3, 4]; 2 | let OTHER_TYPES = [5, 6]; 3 | 4 | export function yes(value) { 5 | return OTHER_TYPES.indexOf(value) >= 0 && ALLOWED_TYPES.indexOf(value) >= 0; 6 | } -------------------------------------------------------------------------------- /test/const-rename/rename.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('const-rename', 'rename'); -------------------------------------------------------------------------------- /test/error-reporting/fixtures/warnings.esm.advanced.js: -------------------------------------------------------------------------------- 1 | console.log(document.getElementById(1)); 2 | -------------------------------------------------------------------------------- /test/error-reporting/fixtures/warnings.esm.default.js: -------------------------------------------------------------------------------- 1 | console.log(document.getElementById(1)); 2 | -------------------------------------------------------------------------------- /test/error-reporting/fixtures/warnings.esm.es5.js: -------------------------------------------------------------------------------- 1 | console.log(document.getElementById(1)); 2 | -------------------------------------------------------------------------------- /test/error-reporting/fixtures/warnings.js: -------------------------------------------------------------------------------- 1 | console.log(document.getElementById(1)); 2 | -------------------------------------------------------------------------------- /test/error-reporting/warnings.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import test from 'ava'; 18 | import compiler from '../../transpile-tests'; 19 | import * as rollup from 'rollup'; 20 | import { promises as fsPromises } from 'fs'; 21 | import { join } from 'path'; 22 | 23 | const closureFlags = { 24 | default: { 25 | warning_level: 'VERBOSE', 26 | language_out: 'ECMASCRIPT5_STRICT', 27 | }, 28 | advanced: { 29 | warning_level: 'VERBOSE', 30 | compilation_level: 'ADVANCED_OPTIMIZATIONS', 31 | language_out: 'ECMASCRIPT5_STRICT', 32 | }, 33 | }; 34 | 35 | async function compile(name, option) { 36 | const bundle = await rollup.rollup({ 37 | input: `test/${name}/fixtures/warnings.js`, 38 | plugins: [compiler(closureFlags[option])], 39 | }); 40 | 41 | return { 42 | minified: await fsPromises.readFile( 43 | join(`test/${name}/fixtures/warnings.esm.${option}.js`), 44 | 'utf8', 45 | ), 46 | code: ( 47 | await bundle.generate({ 48 | format: 'es', 49 | sourcemap: true, 50 | }) 51 | ).code, 52 | }; 53 | } 54 | 55 | Object.keys(closureFlags).forEach(option => { 56 | test(`provides warnings – es, ${option}`, async t => { 57 | try { 58 | await compile('error-reporting', option); 59 | t.fail('successfully built files without warning about input'); 60 | } catch (e) { 61 | t.pass(); 62 | } 63 | }); 64 | }); 65 | -------------------------------------------------------------------------------- /test/export-all/all-external.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2019 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import test from 'ava'; 18 | import { compile } from '../generator'; 19 | 20 | test.serial('export * is unsupported', async t => { 21 | try { 22 | await compile('export-all', 'all-external', false, {default:{}}, 'default', 'esm'); 23 | 24 | t.fail('expected error, but passed'); 25 | } catch(e) { 26 | t.is(e.message, 'Rollup Plugin Closure Compiler does not support export all syntax for externals.'); 27 | } 28 | }); 29 | 30 | -------------------------------------------------------------------------------- /test/export-all/all.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('export-all', 'all'); 20 | -------------------------------------------------------------------------------- /test/export-all/fixtures/all-external.esm.default.js: -------------------------------------------------------------------------------- 1 | export * from './external.js'; 2 | -------------------------------------------------------------------------------- /test/export-all/fixtures/all-external.js: -------------------------------------------------------------------------------- 1 | export * from './external.js'; 2 | -------------------------------------------------------------------------------- /test/export-all/fixtures/all.esm.advanced.js: -------------------------------------------------------------------------------- 1 | var export1=1;function export2(){return 2};export{export1,export2} 2 | -------------------------------------------------------------------------------- /test/export-all/fixtures/all.esm.default.js: -------------------------------------------------------------------------------- 1 | var export1=1;function export2(){return 2};export{export1,export2} 2 | -------------------------------------------------------------------------------- /test/export-all/fixtures/all.esm.es5.js: -------------------------------------------------------------------------------- 1 | var export1=1;function export2(){return 2};export{export1,export2} 2 | -------------------------------------------------------------------------------- /test/export-all/fixtures/all.esm.pretty.js: -------------------------------------------------------------------------------- 1 | 2 | var export1=1; 3 | function export2(){ 4 | return 2; 5 | };export{export1,export2} 6 | -------------------------------------------------------------------------------- /test/export-all/fixtures/all.js: -------------------------------------------------------------------------------- 1 | export * from './dep.js'; 2 | -------------------------------------------------------------------------------- /test/export-all/fixtures/dep.js: -------------------------------------------------------------------------------- 1 | export const export1 = 1; 2 | export function export2() { 3 | return 2; 4 | } 5 | -------------------------------------------------------------------------------- /test/export-all/fixtures/external.js: -------------------------------------------------------------------------------- 1 | export const export1 = 1; 2 | export function export2() { 3 | return 2; 4 | } 5 | -------------------------------------------------------------------------------- /test/export-cjs/export-cjs-extern.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2019 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import test from 'ava'; 18 | import { create } from '../../transpile-tests/transformers/chunk/transforms'; 19 | import { defaults } from '../../transpile-tests/options'; 20 | import { promises as fsPromises } from 'fs'; 21 | 22 | test('generate extern for cjs export pattern', async t => { 23 | const externFixtureContent = await fsPromises.readFile( 24 | 'test/export-cjs/fixtures/export.extern.js', 25 | 'utf8', 26 | ); 27 | const outputOptions = { 28 | format: 'cjs', 29 | }; 30 | 31 | const transforms = create({}); 32 | const options = await defaults(outputOptions, [], transforms); 33 | 34 | for (const externFilePath of options.externs) { 35 | const fileContent = await fsPromises.readFile(externFilePath, 'utf8'); 36 | if (fileContent === externFixtureContent) { 37 | t.pass(); 38 | return; 39 | } 40 | } 41 | t.fail('None of the externs match the expected format'); 42 | }); 43 | -------------------------------------------------------------------------------- /test/export-cjs/fixtures/export.extern.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview Externs built via derived configuration from Rollup or input code. 3 | * This extern contains the cjs typing info for modules. 4 | * @externs 5 | */ 6 | 7 | /** 8 | * @typedef {{ 9 | * __esModule: boolean, 10 | * }} 11 | */ 12 | var exports; -------------------------------------------------------------------------------- /test/export-default/array.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('export-default', 'array'); -------------------------------------------------------------------------------- /test/export-default/arrow-function.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2019 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('export-default', 'arrow-function'); -------------------------------------------------------------------------------- /test/export-default/class.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('export-default', 'class'); -------------------------------------------------------------------------------- /test/export-default/fixtures/array.esm.advanced.js: -------------------------------------------------------------------------------- 1 | export default [] 2 | -------------------------------------------------------------------------------- /test/export-default/fixtures/array.esm.default.js: -------------------------------------------------------------------------------- 1 | export default [] 2 | -------------------------------------------------------------------------------- /test/export-default/fixtures/array.esm.es5.js: -------------------------------------------------------------------------------- 1 | export default [] 2 | -------------------------------------------------------------------------------- /test/export-default/fixtures/array.esm.pretty.js: -------------------------------------------------------------------------------- 1 | 2 | export default [] 3 | -------------------------------------------------------------------------------- /test/export-default/fixtures/array.js: -------------------------------------------------------------------------------- 1 | export default []; -------------------------------------------------------------------------------- /test/export-default/fixtures/arrow-function.esm.advanced.js: -------------------------------------------------------------------------------- 1 | export default a=>console.log(a) 2 | -------------------------------------------------------------------------------- /test/export-default/fixtures/arrow-function.esm.default.js: -------------------------------------------------------------------------------- 1 | export default a=>console.log(a) 2 | -------------------------------------------------------------------------------- /test/export-default/fixtures/arrow-function.esm.es5.js: -------------------------------------------------------------------------------- 1 | export default function(a){return console.log(a)} 2 | -------------------------------------------------------------------------------- /test/export-default/fixtures/arrow-function.esm.pretty.js: -------------------------------------------------------------------------------- 1 | 2 | export default a => console.log(a) 3 | -------------------------------------------------------------------------------- /test/export-default/fixtures/arrow-function.js: -------------------------------------------------------------------------------- 1 | export default a=>console.log(a); -------------------------------------------------------------------------------- /test/export-default/fixtures/class.esm.advanced.js: -------------------------------------------------------------------------------- 1 | class a{constructor(b){this.g=b}console(){console.log(this.g)}}export default a 2 | -------------------------------------------------------------------------------- /test/export-default/fixtures/class.esm.default.js: -------------------------------------------------------------------------------- 1 | class a{constructor(b){this.name_=b}console(){console.log(this.name_)}}export default a 2 | -------------------------------------------------------------------------------- /test/export-default/fixtures/class.esm.es5.js: -------------------------------------------------------------------------------- 1 | function a(b){this.name_=b}a.prototype.console=function(){console.log(this.name_)};export default a 2 | -------------------------------------------------------------------------------- /test/export-default/fixtures/class.esm.pretty.js: -------------------------------------------------------------------------------- 1 | 2 | class a { 3 | constructor(b) { 4 | this.name_ = b; 5 | } 6 | console() { 7 | console.log(this.name_); 8 | } 9 | } 10 | export default a 11 | -------------------------------------------------------------------------------- /test/export-default/fixtures/class.js: -------------------------------------------------------------------------------- 1 | export default class { 2 | constructor(name) { 3 | /** 4 | * @private {string} 5 | */ 6 | this.name_ = name; 7 | } 8 | 9 | console() { 10 | console.log(this.name_); 11 | } 12 | } -------------------------------------------------------------------------------- /test/export-default/fixtures/function.esm.advanced.js: -------------------------------------------------------------------------------- 1 | export default function(a){console.log(a);console.log(1)} 2 | -------------------------------------------------------------------------------- /test/export-default/fixtures/function.esm.default.js: -------------------------------------------------------------------------------- 1 | export default function(a){console.log(a);console.log(1)} 2 | -------------------------------------------------------------------------------- /test/export-default/fixtures/function.esm.es5.js: -------------------------------------------------------------------------------- 1 | export default function(a){console.log(a);console.log(1)} 2 | -------------------------------------------------------------------------------- /test/export-default/fixtures/function.esm.pretty.js: -------------------------------------------------------------------------------- 1 | 2 | export default function(a) { 3 | console.log(a); 4 | console.log(1); 5 | } 6 | -------------------------------------------------------------------------------- /test/export-default/fixtures/function.js: -------------------------------------------------------------------------------- 1 | export default function(argument) { 2 | console.log(argument); 3 | console.log(1); 4 | } -------------------------------------------------------------------------------- /test/export-default/fixtures/identifier.esm.advanced.js: -------------------------------------------------------------------------------- 1 | export default 1 2 | -------------------------------------------------------------------------------- /test/export-default/fixtures/identifier.esm.default.js: -------------------------------------------------------------------------------- 1 | export default 1 2 | -------------------------------------------------------------------------------- /test/export-default/fixtures/identifier.esm.es5.js: -------------------------------------------------------------------------------- 1 | export default 1 2 | -------------------------------------------------------------------------------- /test/export-default/fixtures/identifier.esm.pretty.js: -------------------------------------------------------------------------------- 1 | 2 | export default 1 3 | -------------------------------------------------------------------------------- /test/export-default/fixtures/identifier.js: -------------------------------------------------------------------------------- 1 | const foo = 1; 2 | export default foo; -------------------------------------------------------------------------------- /test/export-default/fixtures/named-class.esm.advanced.js: -------------------------------------------------------------------------------- 1 | class a{constructor(b){this.g=b}console(){console.log(this.g)}}export default a 2 | -------------------------------------------------------------------------------- /test/export-default/fixtures/named-class.esm.default.js: -------------------------------------------------------------------------------- 1 | class a{constructor(b){this.name_=b}console(){console.log(this.name_)}}export default a 2 | -------------------------------------------------------------------------------- /test/export-default/fixtures/named-class.esm.es5.js: -------------------------------------------------------------------------------- 1 | function a(b){this.name_=b}a.prototype.console=function(){console.log(this.name_)};export default a 2 | -------------------------------------------------------------------------------- /test/export-default/fixtures/named-class.esm.pretty.js: -------------------------------------------------------------------------------- 1 | 2 | class a { 3 | constructor(b) { 4 | this.name_ = b; 5 | } 6 | console() { 7 | console.log(this.name_); 8 | } 9 | } 10 | export default a 11 | -------------------------------------------------------------------------------- /test/export-default/fixtures/named-class.js: -------------------------------------------------------------------------------- 1 | export default class Exported { 2 | constructor(name) { 3 | /** 4 | * @private {string} 5 | */ 6 | this.name_ = name; 7 | } 8 | 9 | console() { 10 | console.log(this.name_); 11 | } 12 | } -------------------------------------------------------------------------------- /test/export-default/fixtures/named-function.esm.advanced.js: -------------------------------------------------------------------------------- 1 | export default function(a){console.log(a);console.log(1)} 2 | -------------------------------------------------------------------------------- /test/export-default/fixtures/named-function.esm.default.js: -------------------------------------------------------------------------------- 1 | export default function(a){console.log(a);console.log(1)} 2 | -------------------------------------------------------------------------------- /test/export-default/fixtures/named-function.esm.es5.js: -------------------------------------------------------------------------------- 1 | export default function(a){console.log(a);console.log(1)} 2 | -------------------------------------------------------------------------------- /test/export-default/fixtures/named-function.esm.pretty.js: -------------------------------------------------------------------------------- 1 | 2 | export default function(a) { 3 | console.log(a); 4 | console.log(1); 5 | } 6 | -------------------------------------------------------------------------------- /test/export-default/fixtures/named-function.js: -------------------------------------------------------------------------------- 1 | export default function exported(argument) { 2 | console.log(argument); 3 | console.log(1); 4 | } -------------------------------------------------------------------------------- /test/export-default/fixtures/number.esm.advanced.js: -------------------------------------------------------------------------------- 1 | export default 42 2 | -------------------------------------------------------------------------------- /test/export-default/fixtures/number.esm.default.js: -------------------------------------------------------------------------------- 1 | export default 42 2 | -------------------------------------------------------------------------------- /test/export-default/fixtures/number.esm.es5.js: -------------------------------------------------------------------------------- 1 | export default 42 2 | -------------------------------------------------------------------------------- /test/export-default/fixtures/number.esm.pretty.js: -------------------------------------------------------------------------------- 1 | 2 | export default 42 3 | -------------------------------------------------------------------------------- /test/export-default/fixtures/number.js: -------------------------------------------------------------------------------- 1 | export default 42; -------------------------------------------------------------------------------- /test/export-default/fixtures/object.esm.advanced.js: -------------------------------------------------------------------------------- 1 | export default {key:"value"} 2 | -------------------------------------------------------------------------------- /test/export-default/fixtures/object.esm.default.js: -------------------------------------------------------------------------------- 1 | export default {key:"value"} 2 | -------------------------------------------------------------------------------- /test/export-default/fixtures/object.esm.es5.js: -------------------------------------------------------------------------------- 1 | export default {key:"value"} 2 | -------------------------------------------------------------------------------- /test/export-default/fixtures/object.esm.pretty.js: -------------------------------------------------------------------------------- 1 | 2 | export default {key:"value", } 3 | -------------------------------------------------------------------------------- /test/export-default/fixtures/object.js: -------------------------------------------------------------------------------- 1 | export default { 2 | key: "value", 3 | }; -------------------------------------------------------------------------------- /test/export-default/function.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('export-default', 'function'); -------------------------------------------------------------------------------- /test/export-default/identifier.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('export-default', 'identifier'); -------------------------------------------------------------------------------- /test/export-default/named-class.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('export-default', 'named-class'); -------------------------------------------------------------------------------- /test/export-default/named-function.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('export-default', 'named-function'); -------------------------------------------------------------------------------- /test/export-default/number.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('export-default', 'number'); -------------------------------------------------------------------------------- /test/export-default/object.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('export-default', 'object'); -------------------------------------------------------------------------------- /test/export-externals/array.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2019 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('export-externals', 'array'); -------------------------------------------------------------------------------- /test/export-externals/class.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2019 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('export-externals', 'class'); -------------------------------------------------------------------------------- /test/export-externals/const-function.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2019 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('export-externals', 'const-function'); -------------------------------------------------------------------------------- /test/export-externals/const-number.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2019 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('export-externals', 'const-number'); -------------------------------------------------------------------------------- /test/export-externals/default.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2019 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('export-externals', 'default'); -------------------------------------------------------------------------------- /test/export-externals/fixtures/array.esm.advanced.js: -------------------------------------------------------------------------------- 1 | export{exportedArray}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/array.esm.default.js: -------------------------------------------------------------------------------- 1 | export{exportedArray}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/array.esm.es5.js: -------------------------------------------------------------------------------- 1 | export{exportedArray}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/array.esm.pretty.js: -------------------------------------------------------------------------------- 1 | export{exportedArray}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/array.js: -------------------------------------------------------------------------------- 1 | export {exportedArray} from './external.js'; 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/class.esm.advanced.js: -------------------------------------------------------------------------------- 1 | export{exportedClass}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/class.esm.default.js: -------------------------------------------------------------------------------- 1 | export{exportedClass}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/class.esm.es5.js: -------------------------------------------------------------------------------- 1 | export{exportedClass}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/class.esm.pretty.js: -------------------------------------------------------------------------------- 1 | export{exportedClass}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/class.js: -------------------------------------------------------------------------------- 1 | export {exportedClass} from './external.js'; 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/const-function.esm.advanced.js: -------------------------------------------------------------------------------- 1 | export{constFunction}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/const-function.esm.default.js: -------------------------------------------------------------------------------- 1 | export{constFunction}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/const-function.esm.es5.js: -------------------------------------------------------------------------------- 1 | export{constFunction}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/const-function.esm.pretty.js: -------------------------------------------------------------------------------- 1 | export{constFunction}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/const-function.js: -------------------------------------------------------------------------------- 1 | export {constFunction} from './external.js'; -------------------------------------------------------------------------------- /test/export-externals/fixtures/const-number.esm.advanced.js: -------------------------------------------------------------------------------- 1 | export{constNumber}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/const-number.esm.default.js: -------------------------------------------------------------------------------- 1 | export{constNumber}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/const-number.esm.es5.js: -------------------------------------------------------------------------------- 1 | export{constNumber}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/const-number.esm.pretty.js: -------------------------------------------------------------------------------- 1 | export{constNumber}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/const-number.js: -------------------------------------------------------------------------------- 1 | export {constNumber} from './external.js'; -------------------------------------------------------------------------------- /test/export-externals/fixtures/default.esm.advanced.js: -------------------------------------------------------------------------------- 1 | export{default as X}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/default.esm.default.js: -------------------------------------------------------------------------------- 1 | export{default as X}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/default.esm.es5.js: -------------------------------------------------------------------------------- 1 | export{default as X}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/default.esm.pretty.js: -------------------------------------------------------------------------------- 1 | export{default as X}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/default.js: -------------------------------------------------------------------------------- 1 | export {default as X} from'./external.js'; 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/external-default.js: -------------------------------------------------------------------------------- 1 | export default function() { 2 | return 'foo'; 3 | } -------------------------------------------------------------------------------- /test/export-externals/fixtures/external.js: -------------------------------------------------------------------------------- 1 | export function exportedFunction() { 2 | return 'foo'; 3 | } 4 | 5 | export const constNumber = 1; 6 | 7 | export const exportedArray = [1,2,3]; 8 | 9 | export const constFunction = function(argument) { 10 | console.log(argument); 11 | }; 12 | 13 | export class ExportedClass { 14 | constructor(name) { 15 | /** 16 | * @private {string} 17 | */ 18 | this.name_ = name; 19 | } 20 | 21 | console() { 22 | console.log(this.name_); 23 | } 24 | } 25 | 26 | export const constObject = { 27 | key: "value", 28 | }; 29 | 30 | export default function() { 31 | return 'bar'; 32 | } -------------------------------------------------------------------------------- /test/export-externals/fixtures/function.esm.advanced.js: -------------------------------------------------------------------------------- 1 | export{exportedFunction}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/function.esm.default.js: -------------------------------------------------------------------------------- 1 | export{exportedFunction}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/function.esm.es5.js: -------------------------------------------------------------------------------- 1 | export{exportedFunction}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/function.esm.pretty.js: -------------------------------------------------------------------------------- 1 | export{exportedFunction}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/function.js: -------------------------------------------------------------------------------- 1 | export {exportedFunction} from './external.js'; -------------------------------------------------------------------------------- /test/export-externals/fixtures/local.esm.advanced.js: -------------------------------------------------------------------------------- 1 | export{exportedFunction as exF}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/local.esm.default.js: -------------------------------------------------------------------------------- 1 | export{exportedFunction as exF}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/local.esm.es5.js: -------------------------------------------------------------------------------- 1 | export{exportedFunction as exF}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/local.esm.pretty.js: -------------------------------------------------------------------------------- 1 | export{exportedFunction as exF}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/local.js: -------------------------------------------------------------------------------- 1 | export {exportedFunction as exF} from './external.js'; -------------------------------------------------------------------------------- /test/export-externals/fixtures/multiple-default.esm.advanced.js: -------------------------------------------------------------------------------- 1 | export{default as Y}from'./external-default.js';export{default as X}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/multiple-default.esm.default.js: -------------------------------------------------------------------------------- 1 | export{default as Y}from'./external-default.js';export{default as X}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/multiple-default.esm.es5.js: -------------------------------------------------------------------------------- 1 | export{default as Y}from'./external-default.js';export{default as X}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/multiple-default.esm.pretty.js: -------------------------------------------------------------------------------- 1 | export{default as Y}from'./external-default.js';export{default as X}from'./external.js' 2 | 3 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/multiple-default.js: -------------------------------------------------------------------------------- 1 | export {default as X} from './external.js'; 2 | export {default as Y} from './external-default.js'; -------------------------------------------------------------------------------- /test/export-externals/fixtures/object.esm.advanced.js: -------------------------------------------------------------------------------- 1 | export{constObject}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/object.esm.default.js: -------------------------------------------------------------------------------- 1 | export{constObject}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/object.esm.es5.js: -------------------------------------------------------------------------------- 1 | export{constObject}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/object.esm.pretty.js: -------------------------------------------------------------------------------- 1 | export{constObject}from'./external.js' 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/object.js: -------------------------------------------------------------------------------- 1 | export {constObject} from './external.js'; -------------------------------------------------------------------------------- /test/export-externals/fixtures/reserve-local-name.esm.advanced.js: -------------------------------------------------------------------------------- 1 | export{exportedFunction as a}from'y.js';a("1") 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/reserve-local-name.esm.default.js: -------------------------------------------------------------------------------- 1 | export{exportedFunction as a}from'y.js';a("1") 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/reserve-local-name.esm.es5.js: -------------------------------------------------------------------------------- 1 | export{exportedFunction as a}from'y.js';a("1") 2 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/reserve-local-name.esm.pretty.js: -------------------------------------------------------------------------------- 1 | export{exportedFunction as a}from'y.js'; 2 | a("1") 3 | -------------------------------------------------------------------------------- /test/export-externals/fixtures/reserve-local-name.js: -------------------------------------------------------------------------------- 1 | export {exportedFunction as a} from 'y.js'; 2 | 3 | a('1'); 4 | -------------------------------------------------------------------------------- /test/export-externals/function.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2019 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('export-externals', 'function'); -------------------------------------------------------------------------------- /test/export-externals/local.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2019 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('export-externals', 'local'); -------------------------------------------------------------------------------- /test/export-externals/multiple-default.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2019 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('export-externals', 'multiple-default'); -------------------------------------------------------------------------------- /test/export-externals/object.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2019 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('export-externals', 'object'); -------------------------------------------------------------------------------- /test/export-externals/reserve-local-name.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2019 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('export-externals', 'reserve-local-name'); -------------------------------------------------------------------------------- /test/export-named/fixtures/identifier-alias.esm.advanced.js: -------------------------------------------------------------------------------- 1 | var a=1;export{a as bar} 2 | -------------------------------------------------------------------------------- /test/export-named/fixtures/identifier-alias.esm.default.js: -------------------------------------------------------------------------------- 1 | var a=1;export{a as bar} 2 | -------------------------------------------------------------------------------- /test/export-named/fixtures/identifier-alias.esm.es5.js: -------------------------------------------------------------------------------- 1 | var a=1;export{a as bar} 2 | -------------------------------------------------------------------------------- /test/export-named/fixtures/identifier-alias.esm.pretty.js: -------------------------------------------------------------------------------- 1 | 2 | var a=1;export{a as bar} 3 | -------------------------------------------------------------------------------- /test/export-named/fixtures/identifier-alias.js: -------------------------------------------------------------------------------- 1 | const a = 1; 2 | export{a as bar}; 3 | -------------------------------------------------------------------------------- /test/export-named/fixtures/identifier-default.esm.advanced.js: -------------------------------------------------------------------------------- 1 | export default 1 2 | -------------------------------------------------------------------------------- /test/export-named/fixtures/identifier-default.esm.default.js: -------------------------------------------------------------------------------- 1 | export default 1 2 | -------------------------------------------------------------------------------- /test/export-named/fixtures/identifier-default.esm.es5.js: -------------------------------------------------------------------------------- 1 | export default 1 2 | -------------------------------------------------------------------------------- /test/export-named/fixtures/identifier-default.esm.pretty.js: -------------------------------------------------------------------------------- 1 | 2 | export default 1 3 | -------------------------------------------------------------------------------- /test/export-named/fixtures/identifier-default.js: -------------------------------------------------------------------------------- 1 | const foo = 1; 2 | export{foo as default}; 3 | -------------------------------------------------------------------------------- /test/export-named/fixtures/identifier.esm.advanced.js: -------------------------------------------------------------------------------- 1 | export var foo=1 2 | -------------------------------------------------------------------------------- /test/export-named/fixtures/identifier.esm.default.js: -------------------------------------------------------------------------------- 1 | export var foo=1 2 | -------------------------------------------------------------------------------- /test/export-named/fixtures/identifier.esm.es5.js: -------------------------------------------------------------------------------- 1 | export var foo=1 2 | -------------------------------------------------------------------------------- /test/export-named/fixtures/identifier.esm.pretty.js: -------------------------------------------------------------------------------- 1 | 2 | export var foo=1 3 | -------------------------------------------------------------------------------- /test/export-named/fixtures/identifier.js: -------------------------------------------------------------------------------- 1 | const foo = 1; 2 | export{foo}; 3 | -------------------------------------------------------------------------------- /test/export-named/fixtures/multiple.esm.advanced.js: -------------------------------------------------------------------------------- 1 | class b{constructor(a){this.g=a}console(){console.log(this.g)}}function bar(){console.log(1)};function baz(a){console.log(a)};var foo=1;export{b as ExportedClass,bar,baz,foo} 2 | -------------------------------------------------------------------------------- /test/export-named/fixtures/multiple.esm.default.js: -------------------------------------------------------------------------------- 1 | class b{constructor(a){this.name_=a}console(){console.log(this.name_)}}function bar(){console.log(1)};function baz(a){console.log(a)};var foo=1;export{b as ExportedClass,bar,baz,foo} 2 | -------------------------------------------------------------------------------- /test/export-named/fixtures/multiple.esm.es5.js: -------------------------------------------------------------------------------- 1 | function b(a){this.name_=a}b.prototype.console=function(){console.log(this.name_)};function bar(){console.log(1)};function baz(a){console.log(a)};var foo=1;export{b as ExportedClass,bar,baz,foo} 2 | -------------------------------------------------------------------------------- /test/export-named/fixtures/multiple.esm.pretty.js: -------------------------------------------------------------------------------- 1 | 2 | class b { 3 | constructor(a) { 4 | this.name_ = a; 5 | } 6 | console() { 7 | console.log(this.name_); 8 | } 9 | } 10 | 11 | function bar(){ 12 | console.log(1); 13 | }; 14 | function baz(a) { 15 | console.log(a); 16 | }; 17 | var foo=1;export{b as ExportedClass,bar,baz,foo} 18 | -------------------------------------------------------------------------------- /test/export-named/fixtures/multiple.js: -------------------------------------------------------------------------------- 1 | const foo = 1; 2 | const bar = function() { 3 | console.log(foo); 4 | } 5 | const baz = function(name) { 6 | console.log(name); 7 | } 8 | class ExportedClass { 9 | constructor(name) { 10 | /** 11 | * @private {string} 12 | */ 13 | this.name_ = name; 14 | } 15 | 16 | console() { 17 | console.log(this.name_); 18 | } 19 | } 20 | export{foo, bar, baz, ExportedClass}; 21 | -------------------------------------------------------------------------------- /test/export-named/identifier-alias.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('export-named', 'identifier-alias'); -------------------------------------------------------------------------------- /test/export-named/identifier-default.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('export-named', 'identifier-default'); -------------------------------------------------------------------------------- /test/export-named/identifier.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('export-named', 'identifier'); -------------------------------------------------------------------------------- /test/export-named/multiple.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('export-named', 'multiple'); -------------------------------------------------------------------------------- /test/export-transpilation/fixtures/named-constant.esm.advanced.js: -------------------------------------------------------------------------------- 1 | var b=Symbol.for("smth");export var isSmth=a=>a&&!!a[b] 2 | -------------------------------------------------------------------------------- /test/export-transpilation/fixtures/named-constant.esm.default.js: -------------------------------------------------------------------------------- 1 | var b=Symbol.for("smth");export var isSmth=a=>a&&!!a[b] 2 | -------------------------------------------------------------------------------- /test/export-transpilation/fixtures/named-constant.esm.es5.js: -------------------------------------------------------------------------------- 1 | var a=a||{};a.scope={};a.arrayIteratorImpl=function(b){var c=0;return function(){return c>>0,a.propertyToPolyfillSymbol[d]=a.IS_SYMBOL_NATIVE?a.global.Symbol(d):a.POLYFILL_PREFIX+b+"$"+ 6 | d),a.defineProperty(f,a.propertyToPolyfillSymbol[d],{configurable:!0,writable:!0,value:c})))};a.initSymbol=function(){}; 7 | a.polyfill("Symbol",function(b){function c(g){if(this instanceof c)throw new TypeError("Symbol is not a constructor");return new e(d+(g||"")+"_"+f++,g)}function e(g,h){this.$jscomp$symbol$id_=g;a.defineProperty(this,"description",{configurable:!0,writable:!0,value:h})}if(b)return b;e.prototype.toString=function(){return this.$jscomp$symbol$id_};var d="jscomp_symbol_"+(1E9*Math.random()>>>0)+"_",f=0;return c},"es6","es3"); 8 | a.polyfill("Symbol.iterator",function(b){if(b)return b;b=Symbol("Symbol.iterator");for(var c="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),e=0;e a && !!a[b] 4 | -------------------------------------------------------------------------------- /test/export-transpilation/fixtures/named-constant.js: -------------------------------------------------------------------------------- 1 | var SMTH = Symbol.for('smth'); 2 | 3 | const isSmth = (smth) => { 4 | return smth && !!smth[SMTH] 5 | }; 6 | 7 | export { isSmth }; -------------------------------------------------------------------------------- /test/export-transpilation/fixtures/named-function.esm.advanced.js: -------------------------------------------------------------------------------- 1 | var b=Symbol.for("smth");export function isSmth(a){return a&&!!a[b]} 2 | -------------------------------------------------------------------------------- /test/export-transpilation/fixtures/named-function.esm.default.js: -------------------------------------------------------------------------------- 1 | var b=Symbol.for("smth");export function isSmth(a){return a&&!!a[b]} 2 | -------------------------------------------------------------------------------- /test/export-transpilation/fixtures/named-function.esm.es5.js: -------------------------------------------------------------------------------- 1 | var a=a||{};a.scope={};a.arrayIteratorImpl=function(b){var c=0;return function(){return c>>0,a.propertyToPolyfillSymbol[d]=a.IS_SYMBOL_NATIVE?a.global.Symbol(d):a.POLYFILL_PREFIX+b+"$"+ 6 | d),a.defineProperty(f,a.propertyToPolyfillSymbol[d],{configurable:!0,writable:!0,value:c})))};a.initSymbol=function(){}; 7 | a.polyfill("Symbol",function(b){function c(g){if(this instanceof c)throw new TypeError("Symbol is not a constructor");return new e(d+(g||"")+"_"+f++,g)}function e(g,h){this.$jscomp$symbol$id_=g;a.defineProperty(this,"description",{configurable:!0,writable:!0,value:h})}if(b)return b;e.prototype.toString=function(){return this.$jscomp$symbol$id_};var d="jscomp_symbol_"+(1E9*Math.random()>>>0)+"_",f=0;return c},"es6","es3"); 8 | a.polyfill("Symbol.iterator",function(b){if(b)return b;b=Symbol("Symbol.iterator");for(var c="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),e=0;e { 24 | const externFixtureContent = await fsPromises.readFile( 25 | 'test/iife/fixtures/iife.extern.js', 26 | 'utf8', 27 | ); 28 | const outputOptions = { 29 | format: 'iife', 30 | name: 'wrapper', 31 | }; 32 | 33 | const transforms = create({}); 34 | const options = await defaults(outputOptions, [], transforms); 35 | 36 | for (const externFilePath of options.externs) { 37 | const fileContent = await fsPromises.readFile(externFilePath, 'utf8'); 38 | if (fileContent === externFixtureContent) { 39 | t.pass(); 40 | return; 41 | } 42 | } 43 | t.fail('None of the externs match the expected format'); 44 | }); 45 | 46 | generator('iife', 'iife-wrapped-safely', undefined, ['iife'], undefined, 'wrapper'); 47 | -------------------------------------------------------------------------------- /test/import/dynamic.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { generator } from '../generator'; 18 | 19 | generator('import', 'dynamic'); 20 | -------------------------------------------------------------------------------- /test/import/external.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('import', 'external'); -------------------------------------------------------------------------------- /test/import/fixtures/chunk-5275c9cc.esm.default.js: -------------------------------------------------------------------------------- 1 | var a=function(){console.log("foo")};var b=function(){console.log("baz")};var c=function(){console.log("bar")};export{a,b,c} 2 | -------------------------------------------------------------------------------- /test/import/fixtures/dynamic-imported-67216f69.esm.advanced.js: -------------------------------------------------------------------------------- 1 | export function handleImport(){return 2} 2 | -------------------------------------------------------------------------------- /test/import/fixtures/dynamic-imported-67216f69.esm.default.js: -------------------------------------------------------------------------------- 1 | export function handleImport(){return 2} 2 | -------------------------------------------------------------------------------- /test/import/fixtures/dynamic-imported-67216f69.esm.es5.js: -------------------------------------------------------------------------------- 1 | export function handleImport(){return 2} 2 | -------------------------------------------------------------------------------- /test/import/fixtures/dynamic-imported-67216f69.esm.pretty.js: -------------------------------------------------------------------------------- 1 | 2 | export function handleImport(){ 3 | return 2; 4 | } 5 | -------------------------------------------------------------------------------- /test/import/fixtures/dynamic-imported.js: -------------------------------------------------------------------------------- 1 | export function handleImport() { 2 | return 2; 3 | } -------------------------------------------------------------------------------- /test/import/fixtures/dynamic.esm.advanced.js: -------------------------------------------------------------------------------- 1 | export function exported(){import("./dynamic-imported-67216f69.js").then(a=>a.g())} 2 | -------------------------------------------------------------------------------- /test/import/fixtures/dynamic.esm.default.js: -------------------------------------------------------------------------------- 1 | export function exported(){import("./dynamic-imported-67216f69.js").then(a=>a.handleImport())} 2 | -------------------------------------------------------------------------------- /test/import/fixtures/dynamic.esm.es5.js: -------------------------------------------------------------------------------- 1 | export function exported(){import("./dynamic-imported-67216f69.js").then(function(a){return a.handleImport()})} 2 | -------------------------------------------------------------------------------- /test/import/fixtures/dynamic.esm.pretty.js: -------------------------------------------------------------------------------- 1 | 2 | export function exported(){ 3 | import("./dynamic-imported-67216f69.js").then(a => a.handleImport()); 4 | } 5 | -------------------------------------------------------------------------------- /test/import/fixtures/dynamic.js: -------------------------------------------------------------------------------- 1 | export function exported() { 2 | import('./dynamic-imported.js').then(module => module.handleImport()); 3 | } -------------------------------------------------------------------------------- /test/import/fixtures/external.esm.advanced.js: -------------------------------------------------------------------------------- 1 | import j from'lodash3';import{thing,thing2}from'lodash2';import _,{foo,bar}from'lodash';console.log("lodash",_,foo,bar,thing,thing2,j) 2 | -------------------------------------------------------------------------------- /test/import/fixtures/external.esm.default.js: -------------------------------------------------------------------------------- 1 | import j from'lodash3';import{thing,thing2}from'lodash2';import _,{foo,bar}from'lodash';console.log("lodash",_,foo,bar,thing,thing2,j) 2 | -------------------------------------------------------------------------------- /test/import/fixtures/external.esm.es5.js: -------------------------------------------------------------------------------- 1 | import j from'lodash3';import{thing,thing2}from'lodash2';import _,{foo,bar}from'lodash';console.log("lodash",_,foo,bar,thing,thing2,j) 2 | -------------------------------------------------------------------------------- /test/import/fixtures/external.esm.pretty.js: -------------------------------------------------------------------------------- 1 | import j from'lodash3';import{thing,thing2}from'lodash2';import _,{foo,bar}from'lodash'; 2 | console.log("lodash", _, foo, bar, thing, thing2, j) 3 | -------------------------------------------------------------------------------- /test/import/fixtures/external.js: -------------------------------------------------------------------------------- 1 | import _, { foo, bar as baz } from 'lodash'; 2 | import {thing, thing2 as thing3} from 'lodash2'; 3 | import j from 'lodash3'; 4 | 5 | console.log('lodash', _, foo, baz, thing, thing3, j); -------------------------------------------------------------------------------- /test/import/fixtures/flattened.esm.advanced.js: -------------------------------------------------------------------------------- 1 | export function exported(a){console.log(a);console.log(1)} 2 | -------------------------------------------------------------------------------- /test/import/fixtures/flattened.esm.default.js: -------------------------------------------------------------------------------- 1 | export function exported(a){console.log(a);console.log(1)} 2 | -------------------------------------------------------------------------------- /test/import/fixtures/flattened.esm.es5.js: -------------------------------------------------------------------------------- 1 | export function exported(a){console.log(a);console.log(1)} 2 | -------------------------------------------------------------------------------- /test/import/fixtures/flattened.esm.pretty.js: -------------------------------------------------------------------------------- 1 | 2 | export function exported(a) { 3 | console.log(a); 4 | console.log(1); 5 | } 6 | -------------------------------------------------------------------------------- /test/import/fixtures/flattened.js: -------------------------------------------------------------------------------- 1 | import {yay} from './imported'; 2 | 3 | export function exported(argument) { 4 | console.log(argument); 5 | console.log(yay); 6 | } -------------------------------------------------------------------------------- /test/import/fixtures/imported.js: -------------------------------------------------------------------------------- 1 | export const yay = 1; 2 | export const baaaa = 2; 3 | export const foo = _ => console.log('foo'); -------------------------------------------------------------------------------- /test/import/fixtures/star.esm.advanced.js: -------------------------------------------------------------------------------- 1 | var a=Object.freeze({__proto__:null,i:1,g:2,h:()=>console.log("foo")});console.log(...a) 2 | -------------------------------------------------------------------------------- /test/import/fixtures/star.esm.default.js: -------------------------------------------------------------------------------- 1 | var a=Object.freeze({__proto__:null,yay:1,baaaa:2,foo:()=>console.log("foo")});console.log(...a) 2 | -------------------------------------------------------------------------------- /test/import/fixtures/star.esm.es5.js: -------------------------------------------------------------------------------- 1 | var b=b||{};b.scope={};b.arrayIteratorImpl=function(a){var c=0;return function(){return c console.log("foo")}); 3 | console.log(...a) 4 | -------------------------------------------------------------------------------- /test/import/fixtures/star.js: -------------------------------------------------------------------------------- 1 | import * as ns from './imported.js'; 2 | 3 | console.log(...ns); -------------------------------------------------------------------------------- /test/import/fixtures/utf8-41b27160.esm.advanced.js: -------------------------------------------------------------------------------- 1 | console.log("foo");console.log("baz");import("./utf8-lazy-527020b7.js");function ɵɵbar(){console.log("bar")};export{ɵɵbar as ɵ} 2 | -------------------------------------------------------------------------------- /test/import/fixtures/utf8-41b27160.esm.default.js: -------------------------------------------------------------------------------- 1 | console.log("foo");console.log("baz");import("./utf8-lazy-527020b7.js");function ɵɵbar(){console.log("bar")};export{ɵɵbar as ɵ} 2 | -------------------------------------------------------------------------------- /test/import/fixtures/utf8-41b27160.esm.es5.js: -------------------------------------------------------------------------------- 1 | console.log("foo");console.log("baz");import("./utf8-lazy-527020b7.js");function ɵɵbar(){console.log("bar")};export{ɵɵbar as ɵ} 2 | -------------------------------------------------------------------------------- /test/import/fixtures/utf8-41b27160.esm.pretty.js: -------------------------------------------------------------------------------- 1 | 2 | console.log("foo"); 3 | console.log("baz"); 4 | import("./utf8-lazy-527020b7.js"); 5 | function ɵɵbar(){ 6 | console.log("bar"); 7 | };export{ɵɵbar as ɵ} 8 | -------------------------------------------------------------------------------- /test/import/fixtures/utf8-common-38fdc940.esm.advanced.js: -------------------------------------------------------------------------------- 1 | function ɵɵbar(){console.log("bar")};function baz(){console.log("baz")};function ɵɵfoo(){console.log("foo")};export{ɵɵbar as a,baz as b,ɵɵfoo as ɵ} 2 | -------------------------------------------------------------------------------- /test/import/fixtures/utf8-common-38fdc940.esm.default.js: -------------------------------------------------------------------------------- 1 | function ɵɵbar(){console.log("bar")};function baz(){console.log("baz")};function ɵɵfoo(){console.log("foo")};export{ɵɵbar as a,baz as b,ɵɵfoo as ɵ} 2 | -------------------------------------------------------------------------------- /test/import/fixtures/utf8-common-38fdc940.esm.es5.js: -------------------------------------------------------------------------------- 1 | function ɵɵbar(){console.log("bar")};function baz(){console.log("baz")};function ɵɵfoo(){console.log("foo")};export{ɵɵbar as a,baz as b,ɵɵfoo as ɵ} 2 | -------------------------------------------------------------------------------- /test/import/fixtures/utf8-common-38fdc940.esm.pretty.js: -------------------------------------------------------------------------------- 1 | 2 | function ɵɵbar(){ 3 | console.log("bar"); 4 | }; 5 | function baz(){ 6 | console.log("baz"); 7 | }; 8 | function ɵɵfoo(){ 9 | console.log("foo"); 10 | };export{ɵɵbar as a,baz as b,ɵɵfoo as ɵ} 11 | -------------------------------------------------------------------------------- /test/import/fixtures/utf8-common.js: -------------------------------------------------------------------------------- 1 | export function ɵɵfoo() { 2 | console.log('foo'); 3 | } 4 | export function ɵɵbar() { 5 | console.log('bar'); 6 | } 7 | export function baz() { 8 | console.log('baz'); 9 | } -------------------------------------------------------------------------------- /test/import/fixtures/utf8-lazy-527020b7.esm.advanced.js: -------------------------------------------------------------------------------- 1 | import{ɵ as ɵɵbar}from'./utf8-41b27160.js';\u0275\u0275bar() 2 | -------------------------------------------------------------------------------- /test/import/fixtures/utf8-lazy-527020b7.esm.default.js: -------------------------------------------------------------------------------- 1 | import{ɵ as ɵɵbar}from'./utf8-41b27160.js';\u0275\u0275bar() 2 | -------------------------------------------------------------------------------- /test/import/fixtures/utf8-lazy-527020b7.esm.es5.js: -------------------------------------------------------------------------------- 1 | import{ɵ as ɵɵbar}from'./utf8-41b27160.js';\u0275\u0275bar() 2 | -------------------------------------------------------------------------------- /test/import/fixtures/utf8-lazy-527020b7.esm.pretty.js: -------------------------------------------------------------------------------- 1 | import{ɵ as ɵɵbar}from'./utf8-41b27160.js'; 2 | \u0275\u0275bar() 3 | -------------------------------------------------------------------------------- /test/import/fixtures/utf8-lazy.js: -------------------------------------------------------------------------------- 1 | import { ɵɵbar } from './utf8-common.js'; 2 | ɵɵbar(); -------------------------------------------------------------------------------- /test/import/fixtures/utf8.esm.advanced.js: -------------------------------------------------------------------------------- 1 | import './utf8-41b27160.js' 2 | -------------------------------------------------------------------------------- /test/import/fixtures/utf8.esm.default.js: -------------------------------------------------------------------------------- 1 | import './utf8-41b27160.js' 2 | -------------------------------------------------------------------------------- /test/import/fixtures/utf8.esm.es5.js: -------------------------------------------------------------------------------- 1 | import './utf8-41b27160.js' 2 | -------------------------------------------------------------------------------- /test/import/fixtures/utf8.esm.pretty.js: -------------------------------------------------------------------------------- 1 | import './utf8-41b27160.js' 2 | -------------------------------------------------------------------------------- /test/import/fixtures/utf8.js: -------------------------------------------------------------------------------- 1 | import { ɵɵfoo, baz } from './utf8-common.js'; 2 | 3 | ɵɵfoo(); 4 | baz(); 5 | 6 | import('./utf8-lazy.js'); -------------------------------------------------------------------------------- /test/import/flattened.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('import', 'flattened'); -------------------------------------------------------------------------------- /test/import/star.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { generator } from '../generator'; 18 | 19 | generator('import', 'star'); 20 | -------------------------------------------------------------------------------- /test/import/utf8.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { 18 | generator, 19 | failureGenerator, 20 | DEFAULT_CLOSURE_OPTIONS, 21 | PRETTY_PRINT_CLOSURE_OPTIONS, 22 | ADVANCED_CLOSURE_OPTIONS, 23 | ES5_STRICT_CLOSURE_OPTIONS, 24 | } from '../generator'; 25 | 26 | generator('import', 'utf8', true, undefined, { 27 | ...DEFAULT_CLOSURE_OPTIONS, 28 | ...PRETTY_PRINT_CLOSURE_OPTIONS, 29 | ...ES5_STRICT_CLOSURE_OPTIONS, 30 | }); 31 | 32 | // Seperate the Advanced Compilation as we work on it. 33 | generator('import', 'utf8', true, undefined, { 34 | ...ADVANCED_CLOSURE_OPTIONS, 35 | }); 36 | -------------------------------------------------------------------------------- /test/literal-computed-keys/fixtures/literal-computed.esm.advanced.js: -------------------------------------------------------------------------------- 1 | console.log({0:"value"}) 2 | -------------------------------------------------------------------------------- /test/literal-computed-keys/fixtures/literal-computed.esm.default.js: -------------------------------------------------------------------------------- 1 | console.log({0:"value"}) 2 | -------------------------------------------------------------------------------- /test/literal-computed-keys/fixtures/literal-computed.esm.es5.js: -------------------------------------------------------------------------------- 1 | var a={};console.log((a[0]="value",a)) 2 | -------------------------------------------------------------------------------- /test/literal-computed-keys/fixtures/literal-computed.esm.pretty.js: -------------------------------------------------------------------------------- 1 | 2 | console.log({0:"value", }) 3 | -------------------------------------------------------------------------------- /test/literal-computed-keys/fixtures/literal-computed.js: -------------------------------------------------------------------------------- 1 | console.log({ 2 | [0]: 'value', 3 | }); -------------------------------------------------------------------------------- /test/literal-computed-keys/fixtures/mixed-keys.esm.advanced.js: -------------------------------------------------------------------------------- 1 | console.log({0:"value",1:"value",2:"value2",3:"value3",4(a){console.log(a)},5(a){console.log(a)}}) 2 | -------------------------------------------------------------------------------- /test/literal-computed-keys/fixtures/mixed-keys.esm.default.js: -------------------------------------------------------------------------------- 1 | console.log({0:"value",1:"value",2:"value2",3:"value3",4(a){console.log(a)},5(a){console.log(a)}}) 2 | -------------------------------------------------------------------------------- /test/literal-computed-keys/fixtures/mixed-keys.esm.es5.js: -------------------------------------------------------------------------------- 1 | var a={};console.log((a["0"]="value",a[1]="value",a[2]="value2",a[3]="value3",a[4]=function(b){console.log(b)},a[5]=function(b){console.log(b)},a)) 2 | -------------------------------------------------------------------------------- /test/literal-computed-keys/fixtures/mixed-keys.esm.pretty.js: -------------------------------------------------------------------------------- 1 | 2 | console.log({0:"value", 1:"value", 2:"value2", 3:"value3", 4(a) { 3 | console.log(a); 4 | }, 5(a) { 5 | console.log(a); 6 | }}) 7 | -------------------------------------------------------------------------------- /test/literal-computed-keys/fixtures/mixed-keys.js: -------------------------------------------------------------------------------- 1 | function bar(value) { 2 | return value; 3 | } 4 | 5 | console.log({ 6 | 0: 'value', 7 | [1]: 'value', 8 | [bar(2)]: 'value2', 9 | [0 + bar(3)]: 'value3', 10 | [4](value) { 11 | console.log(bar(value)); 12 | }, 13 | 5(value) { 14 | console.log(bar(value)); 15 | } 16 | }); -------------------------------------------------------------------------------- /test/literal-computed-keys/fixtures/spread-expression.esm.advanced.js: -------------------------------------------------------------------------------- 1 | let a=["put","add","delete","clear"];export function SpreadExpression(){return Object.assign({},a,{get:()=>console.log("get thing")})} 2 | -------------------------------------------------------------------------------- /test/literal-computed-keys/fixtures/spread-expression.esm.default.js: -------------------------------------------------------------------------------- 1 | let a=["put","add","delete","clear"];export function SpreadExpression(){return{...a,get:()=>console.log("get thing")}} 2 | -------------------------------------------------------------------------------- /test/literal-computed-keys/fixtures/spread-expression.esm.es5.js: -------------------------------------------------------------------------------- 1 | var a=["put","add","delete","clear"];export function SpreadExpression(){return Object.assign({},a,{get:function(){return console.log("get thing")}})} 2 | -------------------------------------------------------------------------------- /test/literal-computed-keys/fixtures/spread-expression.esm.pretty.js: -------------------------------------------------------------------------------- 1 | 2 | let a = ["put", "add", "delete", "clear"]; 3 | export function SpreadExpression(){ 4 | return {...a, get:() => console.log("get thing"), }; 5 | } 6 | -------------------------------------------------------------------------------- /test/literal-computed-keys/fixtures/spread-expression.js: -------------------------------------------------------------------------------- 1 | const A = ['put', 'add', 'delete', 'clear']; 2 | 3 | export function SpreadExpression(yep) { 4 | return { 5 | ...A, 6 | get: (thing) => console.log('get thing'), 7 | } 8 | } -------------------------------------------------------------------------------- /test/literal-computed-keys/literal-computed.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('literal-computed-keys', 'literal-computed'); -------------------------------------------------------------------------------- /test/literal-computed-keys/mixed-keys.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('literal-computed-keys', 'mixed-keys'); -------------------------------------------------------------------------------- /test/literal-computed-keys/spread-expression.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { generator } from '../generator'; 18 | 19 | generator('literal-computed-keys', 'spread-expression'); 20 | -------------------------------------------------------------------------------- /test/mangle/fixtures/reassign-arrow.esm.default.js: -------------------------------------------------------------------------------- 1 | import j from'lodash3';import{thing,thing2}from'lodash2';import _,{foo,bar as bar$1}from'lodash';var arrowInitial=()=>console.log("initial",{_,foo,bar,baz:bar$1,thing,thing3:thing2,j});var arrowReassigned=()=>{console.log("reassigned",{_:"reassigned _",foo:"reassigned foo",bar:"reassigned bar",baz:"reassigned baz",thing:"reassigned thing",thing3:"reassigned thing3",j:"reassigned j"})};export{arrowInitial,arrowReassigned} 2 | -------------------------------------------------------------------------------- /test/mangle/fixtures/reassign-arrow.js: -------------------------------------------------------------------------------- 1 | import _, { foo, bar as baz } from 'lodash'; 2 | import {thing, thing2 as thing3} from 'lodash2'; 3 | import j from 'lodash3'; 4 | 5 | export const arrowReassigned = () => { 6 | const _ = 'reassigned _'; 7 | const foo = 'reassigned foo'; 8 | const bar = 'reassigned bar'; 9 | const baz = 'reassigned baz'; 10 | const thing = 'reassigned thing'; 11 | const thing3 = 'reassigned thing3'; 12 | const j = 'reassigned j'; 13 | 14 | console.log('reassigned', {_, foo, bar, baz, thing, thing3, j}); 15 | }; 16 | 17 | export const arrowInitial = () => console.log('initial', {_, foo, bar, baz, thing, thing3, j}); 18 | -------------------------------------------------------------------------------- /test/mangle/fixtures/reassign-function.esm.default.js: -------------------------------------------------------------------------------- 1 | import _ from'lodash';function reassigned(){console.log("reassigned",{_:"reassigned _"})};function initial(){console.log("initial",{_});console.log(_)};export{reassigned,initial} 2 | -------------------------------------------------------------------------------- /test/mangle/fixtures/reassign-function.js: -------------------------------------------------------------------------------- 1 | import _ from 'lodash'; 2 | 3 | export function reassigned() { 4 | const _ = 'reassigned _'; 5 | 6 | let initial = initial; 7 | initial(); 8 | 9 | console.log('reassigned', {_}); 10 | } 11 | 12 | export function initial() { 13 | console.log('initial', {_}); 14 | 15 | { 16 | console.log(_); 17 | } 18 | } 19 | 20 | export {reassigned as foo}; -------------------------------------------------------------------------------- /test/mangle/fixtures/test-function.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ampproject/rollup-plugin-closure-compiler/7ec95e00d7cc08e9fb168e0eb5a3e2ff66a0d5d7/test/mangle/fixtures/test-function.js -------------------------------------------------------------------------------- /test/mangle/reassign-arrow.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { generator, DEFAULT_CLOSURE_OPTIONS } from '../generator'; 18 | 19 | generator('mangle', 'reassign-arrow', undefined, undefined, { 20 | ...DEFAULT_CLOSURE_OPTIONS, 21 | }); 22 | -------------------------------------------------------------------------------- /test/mangle/reassign-function.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { generator, DEFAULT_CLOSURE_OPTIONS } from '../generator'; 18 | 19 | generator('mangle', 'reassign-arrow', undefined, undefined, { 20 | ...DEFAULT_CLOSURE_OPTIONS, 21 | }); 22 | -------------------------------------------------------------------------------- /test/provided-externs/class.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { 18 | generator, 19 | DEFAULT_CLOSURE_OPTIONS, 20 | PRETTY_PRINT_CLOSURE_OPTIONS, 21 | ADVANCED_CLOSURE_OPTIONS, 22 | ES5_STRICT_CLOSURE_OPTIONS, 23 | } from '../generator'; 24 | const path = require('path'); 25 | 26 | const EXTERNS = path.resolve('test', 'provided-externs', 'fixtures', 'class.externs.js'); 27 | 28 | generator('provided-externs', 'class', false, undefined, { 29 | default: { 30 | ...DEFAULT_CLOSURE_OPTIONS.default, 31 | externs: EXTERNS, 32 | }, 33 | pretty: { 34 | ...PRETTY_PRINT_CLOSURE_OPTIONS.pretty, 35 | externs: EXTERNS, 36 | }, 37 | advanced: { 38 | ...ADVANCED_CLOSURE_OPTIONS.advanced, 39 | externs: EXTERNS, 40 | }, 41 | es5: { 42 | ...ES5_STRICT_CLOSURE_OPTIONS.es5, 43 | externs: EXTERNS, 44 | }, 45 | }); 46 | -------------------------------------------------------------------------------- /test/provided-externs/fixtures/class.esm.advanced.js: -------------------------------------------------------------------------------- 1 | class a{constructor(b){this.g=b}console(){console.log(this.g)}}export var ExportThis=a 2 | -------------------------------------------------------------------------------- /test/provided-externs/fixtures/class.esm.default.js: -------------------------------------------------------------------------------- 1 | class a{constructor(b){this.name_=b}console(){console.log(this.name_)}}export var ExportThis=a 2 | -------------------------------------------------------------------------------- /test/provided-externs/fixtures/class.esm.es5.js: -------------------------------------------------------------------------------- 1 | function a(b){this.name_=b}a.prototype.console=function(){console.log(this.name_)};export var ExportThis=a 2 | -------------------------------------------------------------------------------- /test/provided-externs/fixtures/class.esm.pretty.js: -------------------------------------------------------------------------------- 1 | 2 | class a { 3 | constructor(b) { 4 | this.name_ = b; 5 | } 6 | console() { 7 | console.log(this.name_); 8 | } 9 | } 10 | export var ExportThis=a 11 | -------------------------------------------------------------------------------- /test/provided-externs/fixtures/class.externs.js: -------------------------------------------------------------------------------- 1 | /** @externs */ 2 | 3 | /** 4 | * @constructor @struct 5 | */ 6 | var Exported = class { 7 | /** 8 | * @param {!string} name 9 | */ 10 | constructor(name) {} 11 | 12 | /** 13 | * @return {string} 14 | */ 15 | console() {} 16 | } -------------------------------------------------------------------------------- /test/provided-externs/fixtures/class.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @implements {Exported} 3 | */ 4 | export class ExportThis { 5 | /** 6 | * @param {!string} name 7 | */ 8 | constructor(name) { 9 | /** 10 | * @private {!string} 11 | */ 12 | this.name_ = name; 13 | } 14 | 15 | /** 16 | * @return {string} 17 | */ 18 | console() { 19 | console.log(this.name_); 20 | } 21 | } -------------------------------------------------------------------------------- /test/provided-externs/multiple-bundles.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | const test = require('ava'); 18 | const path = require('path'); 19 | const rollup = require('rollup'); 20 | const { default: compiler } = require('../../transpile-tests/index'); 21 | 22 | const options = { 23 | externs: [path.resolve('test', 'provided-externs', 'fixtures', 'class.externs.js')], 24 | compilation_level: 'ADVANCED', 25 | }; 26 | const optionsCopy = { ...options }; 27 | 28 | async function compile() { 29 | const bundle = await rollup.rollup({ 30 | input: 'test/provided-externs/fixtures/class.js', 31 | plugins: [compiler(options)], 32 | }); 33 | 34 | await bundle.generate({ 35 | format: 'es', 36 | sourcemap: true, 37 | }); 38 | } 39 | 40 | test(`building does not modify passed configuration`, async t => { 41 | await compile(); 42 | 43 | t.deepEqual(options, optionsCopy); 44 | }); 45 | -------------------------------------------------------------------------------- /test/strict-removal/fixtures/mjs-suffix.iife.default.mjs: -------------------------------------------------------------------------------- 1 | var modular=function(a){a.thing=1;return a}({}) 2 | -------------------------------------------------------------------------------- /test/strict-removal/fixtures/mjs-suffix.mjs: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | export const thing = 1; -------------------------------------------------------------------------------- /test/strict-removal/fixtures/option.iife.default.js: -------------------------------------------------------------------------------- 1 | (function(a){a.thing=1;return a})({}) 2 | -------------------------------------------------------------------------------- /test/strict-removal/fixtures/option.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | export const thing = 1; -------------------------------------------------------------------------------- /test/strict-removal/fixtures/top-level.esm.advanced.js: -------------------------------------------------------------------------------- 1 | export var thing=1 2 | -------------------------------------------------------------------------------- /test/strict-removal/fixtures/top-level.esm.default.js: -------------------------------------------------------------------------------- 1 | export var thing=1 2 | -------------------------------------------------------------------------------- /test/strict-removal/fixtures/top-level.esm.es5.js: -------------------------------------------------------------------------------- 1 | export var thing=1 2 | -------------------------------------------------------------------------------- /test/strict-removal/fixtures/top-level.esm.pretty.js: -------------------------------------------------------------------------------- 1 | 2 | export var thing=1 3 | -------------------------------------------------------------------------------- /test/strict-removal/fixtures/top-level.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | export const thing = 1; -------------------------------------------------------------------------------- /test/strict-removal/mjs-suffix.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | const test = require('ava'); 18 | const { default: compiler } = require('../../transpile-tests/index'); 19 | const rollup = require('rollup'); 20 | const fs = require('fs'); 21 | const path = require('path'); 22 | 23 | test('remove strict declaration from .mjs input', async t => { 24 | const bundle = await rollup.rollup({ 25 | input: 'test/strict-removal/fixtures/mjs-suffix.mjs', 26 | plugins: [compiler()], 27 | onwarn: _ => null, 28 | }); 29 | 30 | const bundles = await bundle.generate({ 31 | format: 'iife', 32 | name: 'modular', 33 | sourcemap: true, 34 | file: 'mjs-suffix.iife.default.mjs' 35 | }); 36 | 37 | const output = []; 38 | if (bundles.output) { 39 | for (const file in bundles.output) { 40 | const minified = await fs.promises.readFile( 41 | path.join('test/strict-removal/fixtures/mjs-suffix.iife.default.mjs'), 42 | 'utf8', 43 | ); 44 | output.push({ 45 | minified, 46 | code: bundles.output[file].code, 47 | }); 48 | } 49 | } 50 | 51 | t.plan(output.length); 52 | for (const result of output) { 53 | t.is(result.code, result.minified); 54 | } 55 | }); 56 | -------------------------------------------------------------------------------- /test/strict-removal/option.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { 18 | generator, 19 | DEFAULT_CLOSURE_OPTIONS, 20 | PRETTY_PRINT_CLOSURE_OPTIONS, 21 | ADVANCED_CLOSURE_OPTIONS, 22 | ES5_STRICT_CLOSURE_OPTIONS, 23 | } from '../generator'; 24 | 25 | const closureOptions = { 26 | default: Object.assign({}, DEFAULT_CLOSURE_OPTIONS.default, { 27 | remove_strict_directive: true, 28 | }), 29 | }; 30 | 31 | generator('strict-removal', 'option', undefined, ['iife'], closureOptions); 32 | -------------------------------------------------------------------------------- /test/strict-removal/top-level.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 The AMP HTML Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS-IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import {generator} from '../generator'; 18 | 19 | generator('strict-removal', 'top-level'); -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": true, 3 | "compilerOptions": { 4 | "lib": [ 5 | "esnext", 6 | ], 7 | "outDir": "transpile", 8 | "sourceMap": true, 9 | "moduleResolution": "node", 10 | "target": "es2019", 11 | "baseUrl": ".", 12 | "allowJs": false, 13 | "noUnusedLocals": true, 14 | "strictNullChecks": true, 15 | "noImplicitAny": true, 16 | "noImplicitThis": true, 17 | "alwaysStrict": true, 18 | "declaration": true, 19 | "module": "esnext", 20 | "allowSyntheticDefaultImports": true, 21 | "incremental": true, 22 | }, 23 | "include": [ 24 | "./**/*.ts", 25 | "./**/*.d.ts", 26 | ] 27 | } -------------------------------------------------------------------------------- /tsconfig.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "module": "commonjs", 5 | "outDir": "transpile-tests", 6 | "esModuleInterop": true 7 | } 8 | } --------------------------------------------------------------------------------