├── .babelrc.js ├── .github ├── actions │ └── ci-setup │ │ └── action.yml └── workflows │ └── ci.yml ├── .gitignore ├── .lintstagedrc ├── .npmrc ├── .prettierignore ├── README.md ├── jest.config.js ├── package.json ├── src └── index.js └── test ├── fixtures ├── annotate │ ├── arguments-nested │ │ ├── code.js │ │ └── output.js │ ├── arguments │ │ ├── code.js │ │ └── output.js │ ├── assignment-expression │ │ ├── code.js │ │ └── output.js │ ├── class-declaration-dynamic-extends │ │ ├── code.js │ │ └── output.js │ ├── class-expression-dynamic-extends │ │ ├── code.js │ │ └── output.js │ ├── export-default │ │ ├── code.js │ │ └── output.js │ ├── named-export │ │ ├── code.js │ │ └── output.js │ ├── new-expression-arguments │ │ ├── code.js │ │ └── output.js │ ├── new-expression │ │ ├── code.js │ │ └── output.js │ ├── outermost-arguments │ │ ├── code.js │ │ └── output.js │ ├── outermost-call-expression │ │ ├── code.js │ │ └── output.js │ ├── outermost-mixed │ │ ├── code.js │ │ └── output.js │ ├── outermost-new-expression │ │ ├── code.js │ │ └── output.js │ ├── pure-iife │ │ ├── code.js │ │ └── output.js │ └── variable-declaration │ │ ├── code.js │ │ └── output.js ├── fixes │ └── callable-expression-has-null-leading-comments │ │ ├── code.js │ │ └── output.js ├── iife │ ├── annotate-in-top-level-nested │ │ ├── code.js │ │ └── output.js │ ├── annotate-in-top-level │ │ ├── code.js │ │ └── output.js │ ├── mixed-iife-types │ │ ├── code.js │ │ └── output.js │ ├── mixed-levels │ │ ├── code.js │ │ └── output.js │ └── skip-in-non-iife-calls │ │ ├── code.js │ │ └── output.js └── skip │ ├── annotated │ ├── code.js │ └── output.js │ ├── implicit-return │ ├── code.js │ └── output.js │ ├── non-top-level │ ├── code.js │ └── output.js │ ├── side-effect-call │ ├── code.js │ └── output.js │ └── side-effect-iife │ ├── code.js │ └── output.js └── index.test.js /.babelrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | [ 4 | '@babel/env', 5 | { 6 | loose: true, 7 | modules: false, 8 | targets: { 9 | node: 18, 10 | }, 11 | }, 12 | ], 13 | ], 14 | } 15 | -------------------------------------------------------------------------------- /.github/actions/ci-setup/action.yml: -------------------------------------------------------------------------------- 1 | name: 'CI setup' 2 | runs: 3 | using: 'composite' 4 | steps: 5 | - name: Use Node.js 20.x 6 | uses: actions/setup-node@v3 7 | with: 8 | node-version: 20.x 9 | 10 | - name: Install Dependencies 11 | run: npm install 12 | shell: bash 13 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | test: 7 | timeout-minutes: 20 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v3 11 | - uses: ./.github/actions/ci-setup 12 | 13 | - name: Test 14 | run: npm run test 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | -------------------------------------------------------------------------------- /.lintstagedrc: -------------------------------------------------------------------------------- 1 | { 2 | "*.{js,md}": [ 3 | "prettier --write", 4 | "git add" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | *output.js 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # babel-plugin-annotate-pure-calls 2 | 3 | [![npm version](https://img.shields.io/npm/v/babel-plugin-annotate-pure-calls.svg)](https://www.npmjs.com/package/babel-plugin-annotate-pure-calls) 4 | [![Build Status](https://travis-ci.org/Andarist/babel-plugin-annotate-pure-calls.svg?branch=master)](https://travis-ci.org/Andarist/babel-plugin-annotate-pure-calls) 5 | [![npm](https://img.shields.io/npm/dm/babel-plugin-annotate-pure-calls.svg)](https://www.npmjs.com/package/babel-plugin-annotate-pure-calls) 6 | 7 | This plugins helps with automatic **#\_\_PURE\_\_** annotation insertion. It add the comment to 8 | [top level call](#top-level-calls) expressions and new expressions in assignment contexts (those are considered by the 9 | plugin as **side effect free**). This helps [UglifyJS](https://github.com/mishoo/UglifyJS2) to perform dead code 10 | elimination more efficiently and therefore reduces the bundle sizes for the consumers. 11 | 12 | **NOTE:** It might break your code, so the caution is advised. Target audience for the plugin are libraries, which in 13 | vast major of use cases do not introduce side effects in top level calls. That doesn't mean that application bundles 14 | cannot benefit from the plugin. 15 | 16 | ## Pure calls 17 | 18 | ```js 19 | // pure call 20 | var inc = add(1) 21 | 22 | // clearly impure - no assignment context 23 | mutate({ prop: 'value' }) 24 | ``` 25 | 26 | ## Top level calls 27 | 28 | Top level call (in terms of this plugin) is one that gets executed during script initialization. So it is every call 29 | located at the root of a file, but also a call in an IIFE that gets executed at startup (including nested ones). 30 | 31 | ```js 32 | var a = topLevelCall() 33 | 34 | b = function() { 35 | noTopLevelCall() 36 | } 37 | 38 | topLevelIIFEs = (function() { 39 | var c = (function() { 40 | var d = (function() { 41 | var e = topLevelCall() 42 | })() 43 | })() 44 | })() 45 | ``` 46 | 47 | ## Installation 48 | 49 | ```sh 50 | npm install --save-dev babel-plugin-annotate-pure-calls 51 | ``` 52 | 53 | ## Usage 54 | 55 | ### Via `.babelrc` (Recommended) 56 | 57 | **.babelrc** 58 | 59 | ```json 60 | { 61 | "plugins": ["annotate-pure-calls"] 62 | } 63 | ``` 64 | 65 | ### Via CLI 66 | 67 | ```sh 68 | babel --plugins annotate-pure-calls script.js 69 | ``` 70 | 71 | ### Via Node API 72 | 73 | ```javascript 74 | require('babel-core').transform('var inc = add(1)', { 75 | plugins: ['annotate-pure-calls'], 76 | }) 77 | ``` 78 | 79 | ### Usage with babel@6 80 | 81 | The plugin works with babel@6, you might see unmet peer dependency warning though. If you want to get rid of it, please 82 | install `@babel/core@6.0.0-bridge.1`. 83 | 84 | ## Similar projects 85 | 86 | - [annotate-pure-call-in-variable-declarator](https://github.com/morlay/babel-plugin-annotate-pure-call-in-variable-declarator) 87 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | transform: {}, 3 | } 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "babel-plugin-annotate-pure-calls", 3 | "version": "0.5.0", 4 | "description": "Babel plugin for annotating automatically pure function calls.", 5 | "author": "Mateusz Burzyński (https://github.com/Andarist)", 6 | "license": "MIT", 7 | "engines": { 8 | "node": ">=18" 9 | }, 10 | "main": "dist/babel-plugin-annotate-pure-calls.cjs.js", 11 | "module": "dist/babel-plugin-annotate-pure-calls.esm.js", 12 | "exports": { 13 | ".": { 14 | "types": { 15 | "import": "./dist/babel-plugin-annotate-pure-calls.cjs.mjs", 16 | "default": "./dist/babel-plugin-annotate-pure-calls.cjs.js" 17 | }, 18 | "module": "./dist/babel-plugin-annotate-pure-calls.esm.js", 19 | "import": "./dist/babel-plugin-annotate-pure-calls.cjs.mjs", 20 | "default": "./dist/babel-plugin-annotate-pure-calls.cjs.js" 21 | }, 22 | "./package.json": "./package.json" 23 | }, 24 | "files": [ 25 | "dist" 26 | ], 27 | "repository": { 28 | "type": "git", 29 | "url": "git+https://github.com/Andarist/babel-plugin-annotate-pure-calls.git" 30 | }, 31 | "keywords": [ 32 | "babel", 33 | "plugin", 34 | "pure", 35 | "side-effects", 36 | "uglifyjs" 37 | ], 38 | "bugs": { 39 | "url": "https://github.com/Andarist/babel-plugin-annotate-pure-calls/issues" 40 | }, 41 | "homepage": "https://github.com/Andarist/babel-plugin-annotate-pure-calls#readme", 42 | "peerDependencies": { 43 | "@babel/core": "^7.0.0" 44 | }, 45 | "devDependencies": { 46 | "@babel/cli": "^7.1.0", 47 | "@babel/core": "^7.1.0", 48 | "@babel/plugin-transform-modules-commonjs": "^7.1.0", 49 | "@babel/preset-env": "^7.1.0", 50 | "@preconstruct/cli": "^2.8.10", 51 | "babel-plugin-tester": "^5.4.0", 52 | "husky": "^0.14.3", 53 | "jest": "^23.1.0", 54 | "lint-staged": "^7.1.3", 55 | "prettier": "^1.13.5" 56 | }, 57 | "scripts": { 58 | "build": "preconstruct build", 59 | "pretest": "npm run build", 60 | "test": "jest", 61 | "precommit": "lint-staged", 62 | "prepare": "npm run build", 63 | "prepublish": "test $(npm -v | tr . '\\n' | head -n 1) -ge '4' || exit 1", 64 | "preversion": "npm test", 65 | "release:patch": "npm version patch && npm publish && git push --follow-tags", 66 | "release:minor": "npm version minor && npm publish && git push --follow-tags", 67 | "release:major": "npm version major && npm publish && git push --follow-tags" 68 | }, 69 | "prettier": { 70 | "lineWidth": 120, 71 | "singleQuote": true, 72 | "semi": false, 73 | "trailingComma": "all", 74 | "proseWrap": "always" 75 | }, 76 | "preconstruct": { 77 | "exports": { 78 | "importConditionDefaultExport": "default" 79 | }, 80 | "___experimentalFlags_WILL_CHANGE_IN_PATCH": { 81 | "importsConditions": true 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | const PURE_ANNOTATION = '#__PURE__' 2 | 3 | const isPureAnnotated = node => { 4 | const { leadingComments } = node 5 | 6 | if (!leadingComments) { 7 | return false 8 | } 9 | 10 | return leadingComments.some(comment => /[@#]__PURE__/.test(comment.value)) 11 | } 12 | 13 | const annotateAsPure = path => { 14 | if (isPureAnnotated(path.node)) { 15 | return 16 | } 17 | path.addComment('leading', PURE_ANNOTATION) 18 | } 19 | 20 | const hasCallableParent = ({ parentPath }) => 21 | parentPath.isCallExpression() || parentPath.isNewExpression() 22 | 23 | const isUsedAsCallee = path => { 24 | if (!hasCallableParent(path)) { 25 | return false 26 | } 27 | 28 | return path.parentPath.get('callee') === path 29 | } 30 | 31 | const isInCallee = path => { 32 | do { 33 | path = path.parentPath 34 | 35 | if (isUsedAsCallee(path)) { 36 | return true 37 | } 38 | } while (!path.isStatement() && !path.isFunction()) 39 | 40 | return false 41 | } 42 | 43 | const isExecutedDuringInitialization = path => { 44 | let functionParent = path.getFunctionParent() 45 | 46 | while (functionParent) { 47 | if (!isUsedAsCallee(functionParent)) { 48 | return false 49 | } 50 | 51 | functionParent = functionParent.getFunctionParent() 52 | } 53 | 54 | return true 55 | } 56 | 57 | const isInAssignmentContext = path => { 58 | const statement = path.getStatementParent() 59 | let parentPath 60 | 61 | do { 62 | ;({ parentPath } = parentPath || path) 63 | 64 | if ( 65 | parentPath.isVariableDeclaration() || 66 | parentPath.isAssignmentExpression() || 67 | parentPath.isClass() 68 | ) { 69 | return true 70 | } 71 | } while (parentPath !== statement) 72 | 73 | return false 74 | } 75 | 76 | const callableExpressionVisitor = path => { 77 | if (isUsedAsCallee(path) || isInCallee(path)) { 78 | return 79 | } 80 | 81 | if (!isExecutedDuringInitialization(path)) { 82 | return 83 | } 84 | 85 | if ( 86 | !isInAssignmentContext(path) && 87 | !path.getStatementParent().isExportDefaultDeclaration() 88 | ) { 89 | return 90 | } 91 | 92 | annotateAsPure(path) 93 | } 94 | 95 | export default () => ({ 96 | name: 'annotate-pure-calls', 97 | visitor: { 98 | 'CallExpression|NewExpression': callableExpressionVisitor, 99 | }, 100 | }) 101 | -------------------------------------------------------------------------------- /test/fixtures/annotate/arguments-nested/code.js: -------------------------------------------------------------------------------- 1 | a = fn(fn2(fn3())) 2 | -------------------------------------------------------------------------------- /test/fixtures/annotate/arguments-nested/output.js: -------------------------------------------------------------------------------- 1 | a = /*#__PURE__*/fn(/*#__PURE__*/fn2(/*#__PURE__*/fn3())); -------------------------------------------------------------------------------- /test/fixtures/annotate/arguments/code.js: -------------------------------------------------------------------------------- 1 | ;(inc = add(one())), (dec = sub(one())) 2 | -------------------------------------------------------------------------------- /test/fixtures/annotate/arguments/output.js: -------------------------------------------------------------------------------- 1 | ; 2 | inc = /*#__PURE__*/add(/*#__PURE__*/one()), dec = /*#__PURE__*/sub(/*#__PURE__*/one()); -------------------------------------------------------------------------------- /test/fixtures/annotate/assignment-expression/code.js: -------------------------------------------------------------------------------- 1 | ;(inc = add(1)), (dec = sub(1)) 2 | -------------------------------------------------------------------------------- /test/fixtures/annotate/assignment-expression/output.js: -------------------------------------------------------------------------------- 1 | ; 2 | inc = /*#__PURE__*/add(1), dec = /*#__PURE__*/sub(1); -------------------------------------------------------------------------------- /test/fixtures/annotate/class-declaration-dynamic-extends/code.js: -------------------------------------------------------------------------------- 1 | const base = bar => 2 | class { 3 | foo() { 4 | return bar 5 | } 6 | } 7 | 8 | class MyClass extends base() {} 9 | -------------------------------------------------------------------------------- /test/fixtures/annotate/class-declaration-dynamic-extends/output.js: -------------------------------------------------------------------------------- 1 | const base = bar => class { 2 | foo() { 3 | return bar; 4 | } 5 | }; 6 | class MyClass extends /*#__PURE__*/base() {} -------------------------------------------------------------------------------- /test/fixtures/annotate/class-expression-dynamic-extends/code.js: -------------------------------------------------------------------------------- 1 | const base = bar => 2 | class { 3 | foo() { 4 | return bar 5 | } 6 | } 7 | 8 | const MyClass = class extends base() {} 9 | -------------------------------------------------------------------------------- /test/fixtures/annotate/class-expression-dynamic-extends/output.js: -------------------------------------------------------------------------------- 1 | const base = bar => class { 2 | foo() { 3 | return bar; 4 | } 5 | }; 6 | const MyClass = class extends /*#__PURE__*/base() {}; -------------------------------------------------------------------------------- /test/fixtures/annotate/export-default/code.js: -------------------------------------------------------------------------------- 1 | export default curry(lighten) 2 | -------------------------------------------------------------------------------- /test/fixtures/annotate/export-default/output.js: -------------------------------------------------------------------------------- 1 | export default /*#__PURE__*/curry(lighten); -------------------------------------------------------------------------------- /test/fixtures/annotate/named-export/code.js: -------------------------------------------------------------------------------- 1 | export const inc = add(1) 2 | -------------------------------------------------------------------------------- /test/fixtures/annotate/named-export/output.js: -------------------------------------------------------------------------------- 1 | export const inc = /*#__PURE__*/add(1); -------------------------------------------------------------------------------- /test/fixtures/annotate/new-expression-arguments/code.js: -------------------------------------------------------------------------------- 1 | a = new MyClass(arg1(), arg2(nestedArg())) 2 | -------------------------------------------------------------------------------- /test/fixtures/annotate/new-expression-arguments/output.js: -------------------------------------------------------------------------------- 1 | a = /*#__PURE__*/new MyClass(/*#__PURE__*/arg1(), /*#__PURE__*/arg2(/*#__PURE__*/nestedArg())); -------------------------------------------------------------------------------- /test/fixtures/annotate/new-expression/code.js: -------------------------------------------------------------------------------- 1 | wait100 = new Promise(resolve => { 2 | setTimeout(resolve, 100) 3 | }) 4 | -------------------------------------------------------------------------------- /test/fixtures/annotate/new-expression/output.js: -------------------------------------------------------------------------------- 1 | wait100 = /*#__PURE__*/new Promise(resolve => { 2 | setTimeout(resolve, 100); 3 | }); -------------------------------------------------------------------------------- /test/fixtures/annotate/outermost-arguments/code.js: -------------------------------------------------------------------------------- 1 | var b = fn(arg1())(arg2())(arg3()) 2 | -------------------------------------------------------------------------------- /test/fixtures/annotate/outermost-arguments/output.js: -------------------------------------------------------------------------------- 1 | var b = /*#__PURE__*/fn(arg1())(arg2())(/*#__PURE__*/arg3()); -------------------------------------------------------------------------------- /test/fixtures/annotate/outermost-call-expression/code.js: -------------------------------------------------------------------------------- 1 | a = fn()()() 2 | -------------------------------------------------------------------------------- /test/fixtures/annotate/outermost-call-expression/output.js: -------------------------------------------------------------------------------- 1 | a = /*#__PURE__*/fn()()(); -------------------------------------------------------------------------------- /test/fixtures/annotate/outermost-mixed/code.js: -------------------------------------------------------------------------------- 1 | a = new (new WeirdoClass()())() 2 | 3 | b = new (new WeirdoClass()())()() 4 | -------------------------------------------------------------------------------- /test/fixtures/annotate/outermost-mixed/output.js: -------------------------------------------------------------------------------- 1 | a = /*#__PURE__*/new (new WeirdoClass()())(); 2 | b = /*#__PURE__*/new (new WeirdoClass()())()(); -------------------------------------------------------------------------------- /test/fixtures/annotate/outermost-new-expression/code.js: -------------------------------------------------------------------------------- 1 | a = new new new WeirdoClass()()() 2 | -------------------------------------------------------------------------------- /test/fixtures/annotate/outermost-new-expression/output.js: -------------------------------------------------------------------------------- 1 | a = /*#__PURE__*/new new new WeirdoClass()()(); -------------------------------------------------------------------------------- /test/fixtures/annotate/pure-iife/code.js: -------------------------------------------------------------------------------- 1 | two = (() => { 2 | return 1 + 1 3 | })() 4 | -------------------------------------------------------------------------------- /test/fixtures/annotate/pure-iife/output.js: -------------------------------------------------------------------------------- 1 | two = /*#__PURE__*/(() => { 2 | return 1 + 1; 3 | })(); -------------------------------------------------------------------------------- /test/fixtures/annotate/variable-declaration/code.js: -------------------------------------------------------------------------------- 1 | var inc = add(1), 2 | dec = sub(1) 3 | -------------------------------------------------------------------------------- /test/fixtures/annotate/variable-declaration/output.js: -------------------------------------------------------------------------------- 1 | var inc = /*#__PURE__*/add(1), 2 | dec = /*#__PURE__*/sub(1); -------------------------------------------------------------------------------- /test/fixtures/fixes/callable-expression-has-null-leading-comments/code.js: -------------------------------------------------------------------------------- 1 | const test = () => {} 2 | /* eslint-disable babel/new-cap */ 3 | export default test() 4 | -------------------------------------------------------------------------------- /test/fixtures/fixes/callable-expression-has-null-leading-comments/output.js: -------------------------------------------------------------------------------- 1 | const test = () => {}; 2 | /* eslint-disable babel/new-cap */ 3 | export default /*#__PURE__*/test(); -------------------------------------------------------------------------------- /test/fixtures/iife/annotate-in-top-level-nested/code.js: -------------------------------------------------------------------------------- 1 | a = (function() { 2 | var b = (function() { 3 | var c = (function() { 4 | var d = call() 5 | })() 6 | })() 7 | })() 8 | -------------------------------------------------------------------------------- /test/fixtures/iife/annotate-in-top-level-nested/output.js: -------------------------------------------------------------------------------- 1 | a = /*#__PURE__*/function () { 2 | var b = /*#__PURE__*/function () { 3 | var c = /*#__PURE__*/function () { 4 | var d = /*#__PURE__*/call(); 5 | }(); 6 | }(); 7 | }(); -------------------------------------------------------------------------------- /test/fixtures/iife/annotate-in-top-level/code.js: -------------------------------------------------------------------------------- 1 | a = (function() { 2 | var inc = add(1) 3 | })() 4 | -------------------------------------------------------------------------------- /test/fixtures/iife/annotate-in-top-level/output.js: -------------------------------------------------------------------------------- 1 | a = /*#__PURE__*/function () { 2 | var inc = /*#__PURE__*/add(1); 3 | }(); -------------------------------------------------------------------------------- /test/fixtures/iife/mixed-iife-types/code.js: -------------------------------------------------------------------------------- 1 | a = (function() { 2 | var b = (() => { 3 | var c = (function() { 4 | var d = call() 5 | })() 6 | })() 7 | })() 8 | -------------------------------------------------------------------------------- /test/fixtures/iife/mixed-iife-types/output.js: -------------------------------------------------------------------------------- 1 | a = /*#__PURE__*/function () { 2 | var b = /*#__PURE__*/(() => { 3 | var c = /*#__PURE__*/function () { 4 | var d = /*#__PURE__*/call(); 5 | }(); 6 | })(); 7 | }(); -------------------------------------------------------------------------------- /test/fixtures/iife/mixed-levels/code.js: -------------------------------------------------------------------------------- 1 | a = (function() { 2 | function b() { 3 | var c = (function() { 4 | var d = call() 5 | })() 6 | } 7 | })() 8 | -------------------------------------------------------------------------------- /test/fixtures/iife/mixed-levels/output.js: -------------------------------------------------------------------------------- 1 | a = /*#__PURE__*/function () { 2 | function b() { 3 | var c = function () { 4 | var d = call(); 5 | }(); 6 | } 7 | }(); -------------------------------------------------------------------------------- /test/fixtures/iife/skip-in-non-iife-calls/code.js: -------------------------------------------------------------------------------- 1 | var foo = curry((a, b) => { 2 | return a() + b() 3 | }) 4 | 5 | foo = obj.prop((a, b) => { 6 | return a() + b() 7 | }) 8 | 9 | foo = arr[index](function(a, b) { 10 | return a() + b() 11 | }) 12 | -------------------------------------------------------------------------------- /test/fixtures/iife/skip-in-non-iife-calls/output.js: -------------------------------------------------------------------------------- 1 | var foo = /*#__PURE__*/curry((a, b) => { 2 | return a() + b(); 3 | }); 4 | foo = /*#__PURE__*/obj.prop((a, b) => { 5 | return a() + b(); 6 | }); 7 | foo = /*#__PURE__*/arr[index](function (a, b) { 8 | return a() + b(); 9 | }); -------------------------------------------------------------------------------- /test/fixtures/skip/annotated/code.js: -------------------------------------------------------------------------------- 1 | var inc = /*#__PURE__*/ add(1) 2 | -------------------------------------------------------------------------------- /test/fixtures/skip/annotated/output.js: -------------------------------------------------------------------------------- 1 | var inc = /*#__PURE__*/add(1); -------------------------------------------------------------------------------- /test/fixtures/skip/implicit-return/code.js: -------------------------------------------------------------------------------- 1 | wait100 = new Promise(resolve => setTimeout(resolve, 100)) 2 | -------------------------------------------------------------------------------- /test/fixtures/skip/implicit-return/output.js: -------------------------------------------------------------------------------- 1 | wait100 = /*#__PURE__*/new Promise(resolve => setTimeout(resolve, 100)); -------------------------------------------------------------------------------- /test/fixtures/skip/non-top-level/code.js: -------------------------------------------------------------------------------- 1 | function inc(a) { 2 | return add(a, 1) 3 | } 4 | -------------------------------------------------------------------------------- /test/fixtures/skip/non-top-level/output.js: -------------------------------------------------------------------------------- 1 | function inc(a) { 2 | return add(a, 1); 3 | } -------------------------------------------------------------------------------- /test/fixtures/skip/side-effect-call/code.js: -------------------------------------------------------------------------------- 1 | fn() 2 | -------------------------------------------------------------------------------- /test/fixtures/skip/side-effect-call/output.js: -------------------------------------------------------------------------------- 1 | fn(); -------------------------------------------------------------------------------- /test/fixtures/skip/side-effect-iife/code.js: -------------------------------------------------------------------------------- 1 | ;(() => console.log('side effect'))() 2 | -------------------------------------------------------------------------------- /test/fixtures/skip/side-effect-iife/output.js: -------------------------------------------------------------------------------- 1 | ; 2 | (() => console.log('side effect'))(); -------------------------------------------------------------------------------- /test/index.test.js: -------------------------------------------------------------------------------- 1 | const babel = require('@babel/core') 2 | const pluginTester = require('babel-plugin-tester') 3 | const annotatePureCallsPlugin = require('..').default 4 | 5 | pluginTester({ 6 | babel, 7 | plugin: annotatePureCallsPlugin, 8 | fixtures: `${__dirname}/fixtures`, 9 | }) 10 | --------------------------------------------------------------------------------