pax_global_header00006660000000000000000000000064135070553620014520gustar00rootroot0000000000000052 comment=9e94593021052b1e48127b59ef0c2f51708b8662 buble-0.19.8/000077500000000000000000000000001350705536200127105ustar00rootroot00000000000000buble-0.19.8/.editorconfig000066400000000000000000000001531350705536200153640ustar00rootroot00000000000000[**.js] indent_style = tab indent_size = 2 end_of_line = lf charset = utf-8 trim_trailing_whitespace = truebuble-0.19.8/.eslintrc.json000066400000000000000000000014601350705536200155050ustar00rootroot00000000000000{ "root": true, "rules": { "indent": [ 2, "tab", { "SwitchCase": 1 } ], "linebreak-style": [ 2, "unix" ], "semi": [ 2, "always" ], "keyword-spacing": [ 2, { "before": true, "after": true } ], "space-before-blocks": [ 2, "always" ], "space-in-parens": [ 2, "never" ], "no-mixed-spaces-and-tabs": [ 2, "smart-tabs" ], "no-cond-assign": [ 0 ], "prefer-const": 2, "no-var": 2 }, "env": { "es6": true, "node": true }, "extends": "eslint:recommended", "parserOptions": { "ecmaVersion": 6, "sourceType": "module" }, "overrides": [ { "files": ["register.js"], "rules": { "no-console": [ 0 ], "no-var": [ 0 ] } } ] } buble-0.19.8/.gitattributes000066400000000000000000000000231350705536200155760ustar00rootroot00000000000000* text=auto eol=lf buble-0.19.8/.gitignore000066400000000000000000000001231350705536200146740ustar00rootroot00000000000000.DS_Store node_modules dist test/**/actual sandbox test/bundlers/package-lock.json buble-0.19.8/.gitlab-ci.yml000066400000000000000000000002171350705536200153440ustar00rootroot00000000000000before_script: - npm install test:0.12: image: node:0.12 script: - npm test test:latest: image: node:latest script: - npm test buble-0.19.8/.travis.yml000066400000000000000000000007751350705536200150320ustar00rootroot00000000000000language: node_js node_js: - "stable" - "4" - "6" - "8" env: global: - BUILD_TIMEOUT=10000 script: - npm run test:register - if [ $TRAVIS_NODE_VERSION -eq 8 ]; then set -e; npm run lint; node_modules/.bin/acorn --ecma3 dist/buble-browser.cjs.js > /dev/null; node_modules/.bin/acorn --ecma3 dist/buble-browser-deps.umd.js > /dev/null; node_modules/.bin/acorn --ecma3 register.js > /dev/null; npm run test:bundlers; fi - node scripts/run_test262.js buble-0.19.8/CHANGELOG.md000066400000000000000000000536441350705536200145350ustar00rootroot00000000000000# buble changelog ## 0.19.8 (2019-07-03) * Allow shebang ([#191](https://github.com/bublejs/buble/pull/191)) * Fix tagged template literal in certain cases ([#190](https://github.com/bublejs/buble/issues/190)) * Fix removing of trailing commas in certain cases ([#194](https://github.com/bublejs/buble/pull/194)) * Make JSX Fragment configurable ([#198](https://github.com/bublejs/buble/issues/198)) * Fix transpiling string-keyed properties with whitespaces before colons ([#200](https://github.com/bublejs/buble/pull/200)) ## 0.19.7 (2019-03-11) * Throw error on dynamic import expression if transform is not disabled * Throw error on async and await if transform is not disabled * Allow await outside of functions * Don't bundle acorn dependencies ([#165](https://github.com/bublejs/buble/pull/165)) * Inline spread elements where possible ([#179](https://github.com/bublejs/buble/pull/179)) * Correctly handle operator precedence for array spread ([#177](https://github.com/bublejs/buble/issues/177)) * Correctly pass-through async arrow functions and methods ([#109](https://github.com/bublejs/buble/issues/109), [#146](https://github.com/bublejs/buble/issues/146)) * Move repository to https://github.com/bublejs/buble * Exclude non-string keys from rest properties ([#149](https://github.com/bublejs/buble/issues/149)) ## 0.19.6 (2018-10-23) * Fix class expressions with heritage in arrow functions ([#150](https://github.com/bublejs/buble/issues/150)) * Support `objectAssign: true` in API as a short-hand for `objectAssign: "Object.assign"` * Bundle all acorn dependencies (for now), but no others ([#159](https://github.com/bublejs/buble/issues/159)) ## 0.19.5 (2018-10-16) * Transpile U+2028 and U+2029 according to stage 4 proposal json-superset * Add `/*@__PURE__*/` annotations to transpiled classes * Update support data * Allow disabling spread properties transpiling * Fix specific edge case with spread and computed properties ([#139](https://github.com/bublejs/buble/issues/139)) * Allow global `return` statements * Don't create unnecessary `this` aliases with loops ([#120](https://github.com/bublejs/buble/issues/120)) * Don't allow getters and setters if IE8 is transpile target ([#20](https://github.com/bublejs/buble/issues/20)) ## 0.19.4 (2018-10-06) * Fix transpiling destructuring assignments in brace-less if statement's bodies ([#152](https://github.com/bublejs/buble/issues/152)) * Fix transpiling const and let after brace-less if statements ([#132](https://github.com/bublejs/buble/issues/132)) * Transpile binary and octal number literals if base prefix is upper-case ([#74](https://github.com/bublejs/buble/issues/74)) * Mark classes as supported in Chrome 48 * Mark destructuring of arrow function arguments as not supported in Firefox < 52 ## 0.19.3 (2018-02-13) * Make sure browser builds are actually valid ES5 (except for the modules build) ## 0.19.2 (2018-02-12) * Correctly specify browser field in package.json ([#107](https://github.com/bublejs/buble/issues/107)) * Fix a compile error about using `super` outside of class methods * Fix transpiling rest properties ## 0.19.1 (2018-02-10) * Fix transpiling let and const if arrow functions are not transpiled (i. e. node: 4) ## 0.19.0 (2018-02-10) ### Enhancements * Add support information for new environments * Add (pass-thru) support for aync generators and for-async-of * Add support for dynamic import ([#102](https://github.com/bublejs/buble/pull/102)) * Add support for JSX fragments ([#62](https://github.com/bublejs/buble/issues/62)) * Add unpkg build and transpile browser build for older environments ([#93](https://github.com/bublejs/buble/issues/93)) * Reuse tagged template quasis ([#67](https://github.com/bublejs/buble/pull/67)) * Transpile trailing commas in new expressions ([#63](https://github.com/bublejs/buble/issues/63)) * Add support for destructuring in for-in and for-of loop heads * Add support for destructuring in catch clause params * Add support for rest properties in assignments ### Fixes * Don't remove commas in comments after the last argument ([#89](https://github.com/bublejs/buble/issues/89)) * Support transformations involving aliasing of variables in block scopes ([#60](https://github.com/bublejs/buble/issues/60)) * Evaluate expression only once with inline default pattern elements * Fix nested object and array patterns, rest properties and default values in for loop heads * Only put own properties in rest properties * Improve declaration of helper variables * Allow modification of mutable variables that shadow a const before declaration ([#59](https://github.com/bublejs/buble/issues/59)) * Correctly detect modification of immutable variables through destructuring assignments * In object methods, support destructuring declarations initialized with a variable having the same name as the method ([#86](https://github.com/bublejs/buble/issues/86)) * Fix properties with string literal keys after computed properties ([#91](https://github.com/bublejs/buble/pull/91)) * Fix methods after computed properties ([#101](https://github.com/bublejs/buble/issues/101)) * Fix short-hand generator methods * Fix template literals in array after spread element ([#105](https://github.com/bublejs/buble/issues/105)) * Fix arrow functions in array after spread element ([#100](https://github.com/bublejs/buble/issues/100)) * Fix arrow functions in new expression after spread element ([#100](https://github.com/bublejs/buble/issues/100)) * Restore decoding HTML entities in JSX ([#104](https://github.com/bublejs/buble/issues/104)) * Correct various entries in support matrix ## 0.18.0 * Allow anonymous functions and classes as default exports ([#37](https://github.com/bublejs/buble/issues/37)) * Handle non-breaking spaces in JSX ([#46](https://github.com/bublejs/buble/issues/46)) * Allow anonymous classes to be assigned to properties ([#33](https://github.com/bublejs/buble/issues/33)) * Add `trailingFunctionCommas` transformation ([#50](https://github.com/bublejs/buble/issues/50)) ## 0.17.3 * Move `chalk` to dependencies ([#35](https://github.com/bublejs/buble/issues/35)) ## 0.17.2 * Fix nested template literals regression ([#39](https://github.com/bublejs/buble/issues/39)) ## 0.17.1 * Error on nested rest elements ([#31](https://github.com/bublejs/buble/pull/31)) * Allow destructuring with computed properties ([#34](https://github.com/bublejs/buble/pull/34)) ## 0.17.0 * Update dependencies * Transpile arrow functions unconditionally if spread arguments need transpilation ([#22](https://github.com/bublejs/buble/pull/22)) * Better object spread support ([#25](https://github.com/bublejs/buble/pull/25)) * Rest properties ([#30](https://github.com/bublejs/buble/pull/30)) * Fix ([#24](https://github.com/bublejs/buble/pull/24)) ## 0.16.0 * Allow truthy dash-cased props ([#2](https://github.com/bublejs/buble/pull/2)) * Make class accessors configurable ([#3](https://github.com/bublejs/buble/pull/3)) * Support JSX pragma comments ([#5](https://github.com/bublejs/buble/pull/5)) * Handle JSX with no spaces between attributes ([#6](https://github.com/bublejs/buble/pull/6)) ## 0.15.2 * Don't create function names for object methods with `namedFunctionExpressions: false` * Simplify destructuring assignment statements * Give unique names to methods that shadow free variables ([#166](https://gitlab.com/Rich-Harris/buble/issues/166)) ## 0.15.1 * Fix `Object.assign` regression ([#163](https://gitlab.com/Rich-Harris/buble/issues/163)) ## 0.15.0 * More informative CLI errors when input comes from stdin ([#155](https://gitlab.com/Rich-Harris/buble/issues/155)) * Prevent PhantomJS shadowing errors ([#154](https://gitlab.com/Rich-Harris/buble/issues/154)) * Use local `register.js` in tests ([#153](https://gitlab.com/Rich-Harris/buble/issues/153)) * Correct CLI output filename with .jsx input ([#151](https://gitlab.com/Rich-Harris/buble/issues/151)) * Fix whitespace removal bug ([#159](https://gitlab.com/Rich-Harris/buble/issues/159)) * Allow computed properties in object destructuring ([#146](https://gitlab.com/Rich-Harris/buble/issues/146)) * Support rest elements in array destructuring ([#147](https://gitlab.com/Rich-Harris/buble/issues/147)) * Fix array swap assignment expression ([#148](https://gitlab.com/Rich-Harris/buble/issues/148)) * Allow template string as destructuring default ([#145](https://gitlab.com/Rich-Harris/buble/issues/145)) * Support multiple returning loops with block scoping ([cbc17ad5e](https://gitlab.com/Rich-Harris/buble/commit/cbc17ad5e1dc6e8af820fee372e6fb68e475afa4)) * Fix `super` with spread arguments ([#129](https://gitlab.com/Rich-Harris/buble/issues/129)) * Arrow function returning computed property ([#126](https://gitlab.com/Rich-Harris/buble/issues/126)) * Allow computed property and object spread to coexist ([#144](https://gitlab.com/Rich-Harris/buble/issues/144)) * Add `namedFunctionExpressions` option to prevent scope leak in old browsers ([#130](https://gitlab.com/Rich-Harris/buble/issues/130)) * Fix exponentiation assignment edge case ([#122](https://gitlab.com/Rich-Harris/buble/issues/122)) * Allow CLI `--output` flag to work with stdin input ## 0.14.3 * Prevent crashing on Node versions more recent than the latest 'supported' version ([#102](https://gitlab.com/Rich-Harris/buble/merge_requests/102)) ## 0.14.2 * Allow `.jsx` file extension ([#127](https://gitlab.com/Rich-Harris/buble/issues/127)) * Handle trailing comma in spread operator ([#133](https://gitlab.com/Rich-Harris/buble/issues/133)) * Allow empty code blocks in JSX ([#131](https://gitlab.com/Rich-Harris/buble/issues/131)) * Allow computed shorthand function name with spread in body ([#135](https://gitlab.com/Rich-Harris/buble/issues/135)) * Add `--objectAssign` CLI option ([#113](https://gitlab.com/Rich-Harris/buble/issues/113)) * Allow numeric literals as shorthand method keys ([#139](https://gitlab.com/Rich-Harris/buble/issues/139)) ## 0.14.1 * fix initialization of block-scoped variables in for-of and for-in loops ([#124](https://gitlab.com/Rich-Harris/buble/issues/124)) ## 0.14.0 * Always wrap block-less bodies in curlies ([#110](https://gitlab.com/Rich-Harris/buble/issues/110), [#117](https://gitlab.com/Rich-Harris/buble/issues/117), [!80](https://gitlab.com/Rich-Harris/buble/merge_requests/80)) * Make sure block-scoped variables in loops have an initializer ([#124](https://gitlab.com/Rich-Harris/buble/issues/124)) * Destructuring assignments ([!82](https://gitlab.com/Rich-Harris/buble/merge_requests/82)) * Support string literals in object destructuring ([!81](https://gitlab.com/Rich-Harris/buble/merge_requests/81)) * Standalone arrow function expression statements ([!79](https://gitlab.com/Rich-Harris/buble/merge_requests/79)) ## 0.13.2 * Fix spread operator when used with `new` and `this` ([#104](https://gitlab.com/Rich-Harris/buble/issues/104), [#115](https://gitlab.com/Rich-Harris/buble/issues/115)) ## 0.13.1 * Handle destructuring in for/for-of loop heads ([#95](https://gitlab.com/Rich-Harris/buble/issues/95)) * Allow early return (without value) from loops ([#103](https://gitlab.com/Rich-Harris/buble/issues/103), [#105](https://gitlab.com/Rich-Harris/buble/issues/105)) ## 0.13.0 * Require an `objectAssign` option to be specified if using object spread operator ([#93](https://gitlab.com/Rich-Harris/buble/issues/93)) * Fix spread operator with expression method calls and template strings ([!74](https://gitlab.com/Rich-Harris/buble/merge_requests/74)) ## 0.12.5 * Prevent reserved words being used as identifiers ([#86](https://gitlab.com/Rich-Harris/buble/issues/86)) * Use correct `this` when transpiling `super` inside arrow function ([#89](https://gitlab.com/Rich-Harris/buble/issues/89)) * Handle body-less `for-of` loops ([#80](https://gitlab.com/Rich-Harris/buble/issues/80)) ## 0.12.4 * Allow references to precede declaration (inside function) in block scoping ([#87](https://gitlab.com/Rich-Harris/buble/issues/87)) ## 0.12.3 * Argh, npm ## 0.12.2 * Files missing in 0.12.1 (???) ## 0.12.1 * Don't require space before parens of shorthand computed method ([#82](https://gitlab.com/Rich-Harris/buble/issues/82)) * Allow string keys for shorthand methods ([#82](https://gitlab.com/Rich-Harris/buble/issues/82)) ## 0.12.0 * Support `u` flag in regular expression literals ([!62](https://gitlab.com/Rich-Harris/buble/merge_requests/62)) * Save `buble/register` transformations to `$HOME/.buble-cache` ([!63](https://gitlab.com/Rich-Harris/buble/merge_requests/63)) ## 0.11.6 * Allow shorthand methods with computed names ([#78](https://gitlab.com/Rich-Harris/buble/issues/78)) * Include code snippet in `error.toString()` ([#79](https://gitlab.com/Rich-Harris/buble/issues/79)) ## 0.11.5 * Preserve whitespace between JSX tags on single line ([#65](https://gitlab.com/Rich-Harris/buble/issues/65)) ## 0.11.4 * Allow computed class methods, except accessors ([!56](https://gitlab.com/Rich-Harris/buble/merge_requests/56)) * Compound destructuring ([!58](https://gitlab.com/Rich-Harris/buble/merge_requests/58)) ## 0.11.3 * Ensure inserted statements follow use strict pragma ([#72](https://gitlab.com/Rich-Harris/buble/issues/72)) ## 0.11.2 * Ensure closing parenthesis is in correct place when transpiling inline computed property object expressions ([#73](https://gitlab.com/Rich-Harris/buble/issues/73)) ## 0.11.1 * Fix computed property followed by non-computed property in inline expression ## 0.11.0 * Computed properties ([#67](https://gitlab.com/Rich-Harris/buble/issues/67)) * Allow `super(...)` to use rest arguments ([#69](https://gitlab.com/Rich-Harris/buble/issues/69)) ## 0.10.7 * Allow customisation of `Object.assign` (used in object spread) ([!51](https://gitlab.com/Rich-Harris/buble/merge_requests/51)) ## 0.10.6 * Handle sparse arrays ([#62](https://gitlab.com/Rich-Harris/buble/issues/62)) * Handle spread expressions in JSX ([#64](https://gitlab.com/Rich-Harris/buble/issues/64)) ## 0.10.5 * Create intermediate directories when transforming via CLI ([#63](https://gitlab.com/Rich-Harris/buble/issues/63)) * Update README ([#57](https://gitlab.com/Rich-Harris/buble/issues/57)) ## 0.10.4 * Support spread operator in object literals ([!45](https://gitlab.com/Rich-Harris/buble/merge_requests/45)) and JSX elements ([!46](https://gitlab.com/Rich-Harris/buble/merge_requests/46)) ## 0.10.3 * Disable intelligent destructuring, temporarily ([#53](https://gitlab.com/Rich-Harris/buble/issues/53)) * Fix whitespace in JSX literals ([!39](https://gitlab.com/Rich-Harris/buble/merge_requests/39)) * Add `: true` to value-less JSX attributes ([!40](https://gitlab.com/Rich-Harris/buble/merge_requests/40)) * Quote invalid attribute names ([!41](https://gitlab.com/Rich-Harris/buble/merge_requests/41)) ## 0.10.2 * Don't add closing quote to JSX component without attributes ([#58](https://gitlab.com/Rich-Harris/buble/issues/58)) ## 0.10.1 * Fix handling of literals inside JSX ## 0.10.0 * Basic JSX support ## 0.9.3 * Better spread operator support, including with `arguments` ([#40](https://gitlab.com/Rich-Harris/buble/issues/40)) * Fix indentation of inserted statements in class constructors ([#39](https://gitlab.com/Rich-Harris/buble/issues/39)) ## 0.9.2 * Allow class to have accessors and no constructor ([#48](https://gitlab.com/Rich-Harris/buble/issues/48)) * Fix help message in CLI ## 0.9.1 * Prevent confusion over `Literal` node keys ## 0.9.0 * More complete and robust destructuring support ([#37](https://gitlab.com/Rich-Harris/buble/issues/37), [#43](https://gitlab.com/Rich-Harris/buble/issues/43)) * Correct `this`/`arguments` references inside for-of loop ## 0.8.5 * Allow destructured parameter to have default ([#43](https://gitlab.com/Rich-Harris/buble/issues/43)) * Allow `continue`/`break` statements inside a for-of loop ## 0.8.4 * Allow class body to follow ID/superclass without whitespace ([#46](https://gitlab.com/Rich-Harris/buble/issues/46)) ## 0.8.3 * Performance enhancements ([!23](https://gitlab.com/Rich-Harris/buble/merge_requests/23)) ## 0.8.2 * More robust version of ([!22](https://gitlab.com/Rich-Harris/buble/merge_requests/22)) ## 0.8.1 * Fix `export default class A extends B` (broken in 0.8.0) ([!22](https://gitlab.com/Rich-Harris/buble/merge_requests/22)) ## 0.8.0 * Subclasses inherit static methods ([#33](https://gitlab.com/Rich-Harris/buble/issues/33)) * Performance enhancements ([!21](https://gitlab.com/Rich-Harris/buble/merge_requests/21)) ## 0.7.1 * Prevent omission of closing paren in template string ([#42](https://gitlab.com/Rich-Harris/buble/issues/42)) * Separate variable declarations for each name in destructured declaration ([#18](https://gitlab.com/Rich-Harris/buble/merge_requests/18)) ## 0.7.0 * Allow arrow functions to be used as default parameter values ([#36](https://gitlab.com/Rich-Harris/buble/issues/36)) ## 0.6.7 * Support `static get` and `set` in classes ([#34](https://gitlab.com/Rich-Harris/buble/issues/34)) * Support spread operator in expression method call ([!14](https://gitlab.com/Rich-Harris/buble/merge_requests/14)) * Fix `for-of` loops with no space after opening paren ([#35](https://gitlab.com/Rich-Harris/buble/issues/35)) ## 0.6.6 * Fix another subclass `super()` bug ([#32](https://gitlab.com/Rich-Harris/buble/issues/32)) ## 0.6.5 * Fix `super()` call in subclass expression ([#32](https://gitlab.com/Rich-Harris/buble/issues/32)) * Less defensive template string parenthesising ([!9](https://gitlab.com/Rich-Harris/buble/merge_requests/9)) ## 0.6.4 * Add Node 6 to support matrix ## 0.6.3 * Handle empty template strings ([#28](https://gitlab.com/Rich-Harris/buble/issues/28)) ## 0.6.2 * Handle body-less do-while blocks ([#27](https://gitlab.com/Rich-Harris/buble/issues/27)) ## 0.6.1 * Always remember to close parens in template strings ## 0.6.0 * Strip unnecessary empty strings from template literals * Intelligent destructuring for object patterns in parameters ([#17](https://gitlab.com/Rich-Harris/buble/issues/17)) ## 0.5.8 * Fix exponentiation assignment operator edge case ## 0.5.7 * Exponentiation operator support ([#24](https://gitlab.com/Rich-Harris/buble/issues/24)) * More informative error messages for for-of and tagged template strings ## 0.5.6 * Add `dangerousTaggedTemplateString` ([!2](https://gitlab.com/Rich-Harris/buble/merge_requests/2)) and `dangerousForOf` ([!3](https://gitlab.com/Rich-Harris/buble/merge_requests/3)) transforms * Prevent deindentation causing errors with removed whitespace in class methods * Use correct identifier with default destructured function parameters ([#23](https://gitlab.com/Rich-Harris/buble/issues/23)) ## 0.5.5 * Ensure `return` is in correct place when creating bodies for arrow functions ([#21](https://gitlab.com/Rich-Harris/buble/issues/21)) * Prevent deindentation of class methods causing breakage with destructuring statements ([#22](https://gitlab.com/Rich-Harris/buble/issues/22)) ## 0.5.4 * Install missing `chalk` dependency * Informative error messages when `buble/register` fails ## 0.5.3 * Add `register.js` to package. Yes I'm an idiot ## 0.5.2 * Add `buble/register` for use with e.g. Mocha ## 0.5.1 * Remove unused dependency ## 0.5.0 * Support `--target`, `--yes` and `--no` in CLI * Compile entire directory of files via CLI * Sourcemap support in CLI * All transforms can be disabled (or errors suppressed) with the `transforms` option (or `--yes` and `--no`, in the CLI) * `import` and `export` will throw an error unless `--no modules` transform is specified * Fix bug with destructuring * Fix bug with block scoping and loops ## 0.4.24 * Throw if `let`/`const` is redeclared, or `var` is redeclared with a `let`/`const` (0.4.22 regression) ## 0.4.23 * Add `buble.VERSION` * Tidy up build process (don't bundle Acorn incorrectly) ## 0.4.22 * Allow double `var` declarations (only throw if `let` or `const` is redeclared) ## 0.4.21 * Add `find` and `findIndex` helpers for 0.12 support ## 0.4.20 * Bump to resolve unknown npm issue ## 0.4.19 * Fix block scoping bug with for loops that don't need to be rewritten as functions ## 0.4.18 * Fix break-inside-switch bug ## 0.4.17 * Support `for...in` loops and block scoping ## 0.4.16 * Add `ie` and `edge` to support matrix ## 0.4.15 * Rewrite reserved properties if specified ([#9](https://gitlab.com/Rich-Harris/buble/issues/9)) ## 0.4.14 * Allow classes to extend expressions ([#15](https://gitlab.com/Rich-Harris/buble/issues/15)) * Experimental (partially implemented) API for disabling transforms based on target environment or custom requirements ## 0.4.13 * Fix return statement bug ## 0.4.12 * More complete and robust transpilation of loops that need to be rewritten as functions to simulate block scoping ([#11](https://gitlab.com/Rich-Harris/buble/issues/11), [#12](https://gitlab.com/Rich-Harris/buble/issues/12), [#13](https://gitlab.com/Rich-Harris/buble/issues/13)) ## 0.4.11 * Remove source-map-support from CLI (only useful during development) ## 0.4.10 * Basic support for spread operator ## 0.4.9 * Support getters and setters on subclasses * Disallow unsupported features e.g. generators ## 0.4.8 * Support getters and setters on classes * Allow identifiers to be renamed in block-scoped destructuring ([#8](https://gitlab.com/Rich-Harris/buble/issues/8)) * Transpile body-less arrow functions correctly ([#9](https://gitlab.com/Rich-Harris/buble/issues/4)) ## 0.4.7 * Add browser version ## 0.4.6 * Report locations of parse/compile errors ([#4](https://gitlab.com/Rich-Harris/buble/issues/4)) ## 0.4.5 * Sourcemap support ## 0.4.4 * Support for class expressions * More robust deconflicting * Various bugfixes ## 0.4.3 * Handle arbitrary whitespace inside template literals ## 0.4.2 * Fix bug-inducing typo ## 0.4.1 * Rest parameters ## 0.4.0 * Self-hosting! ## 0.3.4 * Class inheritance ## 0.3.3 * Handle quote marks in template literals ## 0.3.2 * Handle empty `class` declarations ## 0.3.1 * Add `bin` to package ## 0.3.0 * (Very) basic CLI * Handle `export default class ...` ## 0.2.2 * Initialise children of Property nodes * Prevent false positives with reference detection ## 0.2.1 * Add missing files ## 0.2.0 * Support for a bunch more ES2015 features ## 0.1.0 * First (experimental) release buble-0.19.8/LICENSE.md000066400000000000000000000021071350705536200143140ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2016 Rich Harris and contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. buble-0.19.8/README.md000066400000000000000000000007111350705536200141660ustar00rootroot00000000000000# Bublé ## The blazing fast, batteries-included ES2015 compiler * Try it out at [buble.surge.sh](https://buble.surge.sh) * Read the docs at [buble.surge.sh/guide](https://buble.surge.sh/guide) ## Quickstart Via the command line... ```bash npm install -g buble buble input.js > output.js ``` ...or via the JavaScript API: ```js var buble = require( 'buble' ); var result = buble.transform( source ); // { code: ..., map: ... } ``` ## License MIT buble-0.19.8/appveyor.yml000066400000000000000000000002731350705536200153020ustar00rootroot00000000000000environment: matrix: - nodejs_version: "stable" version: "{build}" build: off deploy: off install: - npm install test_script: - node --version - npm --version - npm test buble-0.19.8/bin/000077500000000000000000000000001350705536200134605ustar00rootroot00000000000000buble-0.19.8/bin/.eslintrc.yaml000066400000000000000000000000531350705536200162430ustar00rootroot00000000000000rules: no-console: "off" no-var: "off" buble-0.19.8/bin/buble000077500000000000000000000007621350705536200145040ustar00rootroot00000000000000#!/usr/bin/env node var minimist = require('minimist'); var command = minimist(process.argv.slice(2), { alias: { // Short options h: 'help', i: 'input', m: 'sourcemap', o: 'output', v: 'version', t: 'target', y: 'yes', n: 'no' } }); if (command.help || (process.argv.length <= 2 && process.stdin.isTTY)) { require('./showHelp')(); } else if (command.version) { console.log('Bublé version ' + require('../package.json').version); } else { require('./runBuble')(command); } buble-0.19.8/bin/handleError.js000066400000000000000000000021671350705536200162710ustar00rootroot00000000000000var chalk = require('chalk'); function print(msg) { console.error(chalk.red(msg)); } var handlers = { MISSING_INPUT_OPTION: () => { print('You must specify an --input (-i) option'); }, MISSING_OUTPUT_DIR: () => { print( 'You must specify an --output (-o) option when compiling a directory of files' ); }, MISSING_OUTPUT_FILE: () => { print( 'You must specify an --output (-o) option when creating a file with a sourcemap' ); }, ONE_AT_A_TIME: () => { print('Bublé can only compile one file/directory at a time'); }, DUPLICATE_IMPORT_OPTIONS: () => { print('use --input, or pass input path as argument – not both'); }, BAD_TARGET: () => { print('illegal --target option'); } }; module.exports = function handleError(err) { var handler; if ((handler = handlers[err && err.code])) { handler(err); } else { if (err.snippet) print('---\n' + err.snippet); print(err.message || err); if (err.stack) { console.error(chalk.grey(err.stack)); } } console.error( 'Type ' + chalk.cyan('buble --help') + ' for help, or visit https://buble.surge.sh/guide/' ); process.exit(1); }; buble-0.19.8/bin/help.md000066400000000000000000000027261350705536200147410ustar00rootroot00000000000000Bublé version <%= version %> ===================================== Usage: buble [options] Basic options: -v, --version Show version number -h, --help Show this help message -i, --input Input (alternative to ) -o, --output Output (if absent, prints to stdout) -m, --sourcemap Generate sourcemap (`-m inline` for inline map) -t, --target Select compilation targets -y, --yes Transforms to always apply (overrides --target) -n, --no Transforms to always skip (overrides --target) --jsx Custom JSX pragma --objectAssign Specify Object.assign or equivalent polyfill --no-named-function-expr Don't output named function expressions Examples: # Compile input.js to output.js buble input.js > output.js # Compile input.js to output.js, write sourcemap to output.js.map buble input.js -o output.js -m # Compile input.js to output.js with inline sourcemap buble input.js -o output.js -m inline # Only use transforms necessary for output.js to run in FF43 and Node 5 buble input.js -o output.js -t firefox:43,node:5 # As above, but use arrow function and destructuring transforms buble input.js -o output.js -t firefox:43,node:5 -y arrow,destructuring # Compile all the files in src/ to dest/ buble src -o dest Notes: * When piping to stdout, only inline sourcemaps are permitted For more information visit http://buble.surge.sh/guide buble-0.19.8/bin/runBuble.js000066400000000000000000000064241350705536200156020ustar00rootroot00000000000000var fs = require('fs'); var path = require('path'); var buble = require('..'); var handleError = require('./handleError.js'); var EOL = require('os').EOL; function compile(from, to, command, options) { try { var stats = fs.statSync(from); if (stats.isDirectory()) { compileDir(from, to, command, options); } else { compileFile(from, to, command, options); } } catch (err) { handleError(err); } } function compileDir(from, to, command, options) { if (!command.output) handleError({ code: 'MISSING_OUTPUT_DIR' }); try { fs.mkdirSync(to); } catch (e) { if (e.code !== 'EEXIST') throw e; } fs.readdirSync(from).forEach(function(file) { compile(path.resolve(from, file), path.resolve(to, file), command, options); }); } function compileFile(from, to, command, options) { var ext = path.extname(from); if (ext !== '.js' && ext !== '.jsm' && ext !== '.es6' && ext !== '.jsx') return; if (to) { var extTo = path.extname(to); to = to.slice(0, -extTo.length) + '.js'; } var source = fs.readFileSync(from, 'utf-8'); var result = buble.transform(source, { target: options.target, transforms: options.transforms, source: from, file: to, jsx: options.jsx, objectAssign: options.objectAssign, namedFunctionExpressions: options.namedFunctionExpressions }); write(result, to, command); } function write(result, to, command) { if (command.sourcemap === 'inline') { result.code += EOL + '//# sourceMappingURL=' + result.map.toUrl(); } else if (command.sourcemap) { if (!to) { handleError({ code: 'MISSING_OUTPUT_FILE' }); } result.code += EOL + '//# sourceMappingURL=' + path.basename(to) + '.map'; fs.writeFileSync(to + '.map', result.map.toString()); } if (to) { fs.writeFileSync(to, result.code); } else { console.log(result.code); } } module.exports = function(command) { if (command._.length > 1) { handleError({ code: 'ONE_AT_A_TIME' }); } if (command._.length === 1) { if (command.input) { handleError({ code: 'DUPLICATE_IMPORT_OPTIONS' }); } command.input = command._[0]; } var options = { target: {}, transforms: {}, jsx: command.jsx, objectAssign: command.objectAssign, namedFunctionExpressions: command['named-function-expr'] !== false }; if (command.target) { if (!/^(?:(\w+):([\d.]+),)*(\w+):([\d.]+)$/.test(command.target)) { handleError({ code: 'BAD_TARGET' }); } command.target .split(',') .map(function(target) { return target.split(':'); }) .forEach(function(pair) { options.target[pair[0]] = pair[1]; }); } if (command.yes) { command.yes.split(',').forEach(function(transform) { options.transforms[transform] = true; }); } if (command.no) { command.no.split(',').forEach(function(transform) { options.transforms[transform] = false; }); } if (command.input) { compile(command.input, command.output, command, options); } else { process.stdin.resume(); process.stdin.setEncoding('utf8'); var source = ''; process.stdin.on('data', function(chunk) { source += chunk; }); process.stdin.on('end', function() { options.source = command.input = 'stdin'; options.file = command.output; try { var result = buble.transform(source, options); write(result, command.output, command); } catch (err) { handleError(err); } }); } }; buble-0.19.8/bin/showHelp.js000066400000000000000000000005061350705536200156100ustar00rootroot00000000000000var fs = require('fs'); var path = require('path'); module.exports = function() { fs.readFile(path.join(__dirname, 'help.md'), (err, result) => { var help; if (err) throw err; help = result .toString() .replace('<%= version %>', require('../package.json').version); console.log('\n' + help + '\n'); }); }; buble-0.19.8/package-lock.json000066400000000000000000001753751350705536200161460ustar00rootroot00000000000000{ "name": "buble", "version": "0.19.8", "lockfileVersion": 1, "requires": true, "dependencies": { "@types/estree": { "version": "0.0.39", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==", "dev": true }, "@types/node": { "version": "10.11.4", "resolved": "https://registry.npmjs.org/@types/node/-/node-10.11.4.tgz", "integrity": "sha512-ojnbBiKkZFYRfQpmtnnWTMw+rzGp/JiystjluW9jgN3VzRwilXddJ6aGQ9V/7iuDG06SBgn7ozW9k3zcAnYjYQ==", "dev": true }, "acorn": { "version": "6.1.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.1.1.tgz", "integrity": "sha512-jPTiwtOxaHNaAPg/dmrJ/beuzLRnXtB0kQPQ8JpotKJgTB6rX6c8mlf315941pyjBSaPg8NHXS9fhP4u17DpGA==" }, "acorn-dynamic-import": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/acorn-dynamic-import/-/acorn-dynamic-import-4.0.0.tgz", "integrity": "sha512-d3OEjQV4ROpoflsnUA8HozoIR504TFxNivYEUi6uwz0IYhBkTDXGuWlNdMtybRt3nqVx/L6XqMt0FxkXuWKZhw==" }, "acorn-jsx": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.0.1.tgz", "integrity": "sha512-HJ7CfNHrfJLlNTzIEUTj43LNWGkqpRLxm3YjAlcD0ACydk9XynzYsCBHxut+iqt+1aBXkx9UP/w/ZqMr13XIzg==" }, "ajv": { "version": "5.5.2", "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", "integrity": "sha1-c7Xuyj+rZT49P5Qis0GtQiBdyWU=", "dev": true, "requires": { "co": "4.6.0", "fast-deep-equal": "1.1.0", "fast-json-stable-stringify": "2.0.0", "json-schema-traverse": "0.3.1" } }, "ajv-keywords": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-2.1.1.tgz", "integrity": "sha1-YXmX/F9gV2iUxDX5QNgZ4TW4B2I=", "dev": true }, "ansi-escapes": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.2.0.tgz", "integrity": "sha512-cBhpre4ma+U0T1oM5fXg7Dy1Jw7zzwv7lt/GoCpr+hDQJoYnKVPLL4dCvSEFMmQurOQvSrwT7SL/DAlhBI97RQ==", "dev": true }, "ansi-regex": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", "dev": true }, "ansi-styles": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", "requires": { "color-convert": "1.9.3" } }, "argparse": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", "dev": true, "requires": { "sprintf-js": "1.0.3" } }, "arr-diff": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/arr-diff/-/arr-diff-2.0.0.tgz", "integrity": "sha1-jzuCf5Vai9ZpaX5KQlasPOrjVs8=", "dev": true, "requires": { "arr-flatten": "1.1.0" } }, "arr-flatten": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/arr-flatten/-/arr-flatten-1.1.0.tgz", "integrity": "sha512-L3hKV5R/p5o81R7O02IGnwpDmkp6E982XhtbuwSe3O4qOtMMMtodicASA1Cny2U+aCXcNpml+m4dPsvsJ3jatg==", "dev": true }, "array-unique": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/array-unique/-/array-unique-0.2.1.tgz", "integrity": "sha1-odl8yvy8JiXMcPrc6zalDFiwGlM=", "dev": true }, "babel-code-frame": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", "integrity": "sha1-Y/1D99weO7fONZR9uP42mj9Yx0s=", "dev": true, "requires": { "chalk": "1.1.3", "esutils": "2.0.2", "js-tokens": "3.0.2" }, "dependencies": { "ansi-regex": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", "dev": true }, "ansi-styles": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", "dev": true }, "chalk": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", "dev": true, "requires": { "ansi-styles": "2.2.1", "escape-string-regexp": "1.0.5", "has-ansi": "2.0.0", "strip-ansi": "3.0.1", "supports-color": "2.0.0" } }, "strip-ansi": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", "dev": true, "requires": { "ansi-regex": "2.1.1" } }, "supports-color": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", "dev": true } } }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "dev": true }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "dev": true, "requires": { "balanced-match": "1.0.0", "concat-map": "0.0.1" } }, "braces": { "version": "1.8.5", "resolved": "https://registry.npmjs.org/braces/-/braces-1.8.5.tgz", "integrity": "sha1-uneWLhLf+WnWt2cR6RS3N4V79qc=", "dev": true, "requires": { "expand-range": "1.8.2", "preserve": "0.2.0", "repeat-element": "1.1.3" } }, "browser-stdout": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", "dev": true }, "buble": { "version": "0.19.6", "resolved": "https://registry.npmjs.org/buble/-/buble-0.19.6.tgz", "integrity": "sha512-9kViM6nJA1Q548Jrd06x0geh+BG2ru2+RMDkIHHgJY/8AcyCs34lTHwra9BX7YdPrZXd5aarkpr/SY8bmPgPdg==", "dev": true, "requires": { "chalk": "2.4.2", "magic-string": "0.25.3", "minimist": "1.2.0", "os-homedir": "1.0.2", "regexpu-core": "4.5.4", "vlq": "1.0.0" }, "dependencies": { "os-homedir": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", "dev": true } } }, "buffer-from": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==", "dev": true }, "builtin-modules": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-2.0.0.tgz", "integrity": "sha512-3U5kUA5VPsRUA3nofm/BXX7GVHKfxz0hOBAPxXrIvHzlDRkQVqEn6yi8QJegxl4LzOHLdvb7XF5dVawa/VVYBg==", "dev": true }, "caller-path": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/caller-path/-/caller-path-0.1.0.tgz", "integrity": "sha1-lAhe9jWB7NPaqSREqP6U6CV3dR8=", "dev": true, "requires": { "callsites": "0.2.0" } }, "callsites": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-0.2.0.tgz", "integrity": "sha1-r6uWJikQp/M8GaV3WCXGnzTjUMo=", "dev": true }, "chalk": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", "requires": { "ansi-styles": "3.2.1", "escape-string-regexp": "1.0.5", "supports-color": "5.5.0" } }, "chardet": { "version": "0.4.2", "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.4.2.tgz", "integrity": "sha1-tUc7M9yXxCTl2Y3IfVXU2KKci/I=", "dev": true }, "circular-json": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/circular-json/-/circular-json-0.3.3.tgz", "integrity": "sha512-UZK3NBx2Mca+b5LsG7bY183pHWt5Y1xts4P3Pz7ENTwGVnJOUWbRb3ocjvX7hx9tq/yTAdclXm9sZ38gNuem4A==", "dev": true }, "cli-cursor": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-2.1.0.tgz", "integrity": "sha1-s12sN2R5+sw+lHR9QdDQ9SOP/LU=", "dev": true, "requires": { "restore-cursor": "2.0.0" } }, "cli-width": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-2.2.0.tgz", "integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk=", "dev": true }, "co": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=", "dev": true }, "color-convert": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", "requires": { "color-name": "1.1.3" } }, "color-name": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" }, "commander": { "version": "2.15.1", "resolved": "https://registry.npmjs.org/commander/-/commander-2.15.1.tgz", "integrity": "sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag==", "dev": true }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "dev": true }, "concat-stream": { "version": "1.6.2", "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", "dev": true, "requires": { "buffer-from": "1.1.1", "inherits": "2.0.4", "readable-stream": "2.3.6", "typedarray": "0.0.6" } }, "console-group": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/console-group/-/console-group-0.3.3.tgz", "integrity": "sha1-bY62uda3V6KJUoT2LQnHrUPyu84=", "dev": true }, "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", "dev": true }, "debug": { "version": "3.2.6", "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", "dev": true, "requires": { "ms": "2.1.2" } }, "deep-is": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", "dev": true }, "diff": { "version": "3.5.0", "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", "dev": true }, "doctrine": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", "integrity": "sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==", "dev": true, "requires": { "esutils": "2.0.2" } }, "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" }, "eslint": { "version": "4.19.1", "resolved": "https://registry.npmjs.org/eslint/-/eslint-4.19.1.tgz", "integrity": "sha512-bT3/1x1EbZB7phzYu7vCr1v3ONuzDtX8WjuM9c0iYxe+cq+pwcKEoQjl7zd3RpC6YOLgnSy3cTN58M2jcoPDIQ==", "dev": true, "requires": { "ajv": "5.5.2", "babel-code-frame": "6.26.0", "chalk": "2.4.2", "concat-stream": "1.6.2", "cross-spawn": "5.1.0", "debug": "3.2.6", "doctrine": "2.1.0", "eslint-scope": "3.7.3", "eslint-visitor-keys": "1.0.0", "espree": "3.5.4", "esquery": "1.0.1", "esutils": "2.0.2", "file-entry-cache": "2.0.0", "functional-red-black-tree": "1.0.1", "glob": "7.1.4", "globals": "11.12.0", "ignore": "3.3.10", "imurmurhash": "0.1.4", "inquirer": "3.3.0", "is-resolvable": "1.1.0", "js-yaml": "3.13.1", "json-stable-stringify-without-jsonify": "1.0.1", "levn": "0.3.0", "lodash": "4.17.11", "minimatch": "3.0.4", "mkdirp": "0.5.1", "natural-compare": "1.4.0", "optionator": "0.8.2", "path-is-inside": "1.0.2", "pluralize": "7.0.0", "progress": "2.0.3", "regexpp": "1.1.0", "require-uncached": "1.0.3", "semver": "5.7.0", "strip-ansi": "4.0.0", "strip-json-comments": "2.0.1", "table": "4.0.2", "text-table": "0.2.0" }, "dependencies": { "cross-spawn": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", "integrity": "sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk=", "dev": true, "requires": { "lru-cache": "4.1.5", "shebang-command": "1.2.0", "which": "1.3.1" } } } }, "eslint-scope": { "version": "3.7.3", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-3.7.3.tgz", "integrity": "sha512-W+B0SvF4gamyCTmUc+uITPY0989iXVfKvhwtmJocTaYoc/3khEHmEmvfY/Gn9HA9VV75jrQECsHizkNw1b68FA==", "dev": true, "requires": { "esrecurse": "4.2.1", "estraverse": "4.2.0" } }, "eslint-visitor-keys": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz", "integrity": "sha512-qzm/XxIbxm/FHyH341ZrbnMUpe+5Bocte9xkmFMzPMjRaZMcXww+MpBptFvtU+79L362nqiLhekCxCxDPaUMBQ==", "dev": true }, "espree": { "version": "3.5.4", "resolved": "https://registry.npmjs.org/espree/-/espree-3.5.4.tgz", "integrity": "sha512-yAcIQxtmMiB/jL32dzEp2enBeidsB7xWPLNiw3IIkpVds1P+h7qF9YwJq1yUNzp2OKXgAprs4F61ih66UsoD1A==", "dev": true, "requires": { "acorn": "5.7.3", "acorn-jsx": "3.0.1" }, "dependencies": { "acorn": { "version": "5.7.3", "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.3.tgz", "integrity": "sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw==", "dev": true }, "acorn-jsx": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-3.0.1.tgz", "integrity": "sha1-r9+UiPsezvyDSPb7IvRk4ypYs2s=", "dev": true, "requires": { "acorn": "3.3.0" }, "dependencies": { "acorn": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-3.3.0.tgz", "integrity": "sha1-ReN/s56No/JbruP/U2niu18iAXo=", "dev": true } } } } }, "esprima": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", "dev": true }, "esquery": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.0.1.tgz", "integrity": "sha512-SmiyZ5zIWH9VM+SRUReLS5Q8a7GxtRdxEBVZpm98rJM7Sb+A9DVCndXfkeFUd3byderg+EbDkfnevfCwynWaNA==", "dev": true, "requires": { "estraverse": "4.2.0" } }, "esrecurse": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.2.1.tgz", "integrity": "sha512-64RBB++fIOAXPw3P9cy89qfMlvZEXZkqqJkjqqXIvzP5ezRZjW+lPWjw35UX/3EhUPFYbg5ER4JYgDw4007/DQ==", "dev": true, "requires": { "estraverse": "4.2.0" } }, "estraverse": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.2.0.tgz", "integrity": "sha1-De4/7TH81GlhjOc0IJn8GvoL2xM=", "dev": true }, "estree-walker": { "version": "0.5.2", "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.5.2.tgz", "integrity": "sha512-XpCnW/AE10ws/kDAs37cngSkvgIR8aN3G0MS85m7dUpuK2EREo9VJ00uvw6Dg/hXEpfsE1I1TvJOJr+Z+TL+ig==", "dev": true }, "esutils": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", "dev": true }, "expand-brackets": { "version": "0.1.5", "resolved": "https://registry.npmjs.org/expand-brackets/-/expand-brackets-0.1.5.tgz", "integrity": "sha1-3wcoTjQqgHzXM6xa9yQR5YHRF3s=", "dev": true, "requires": { "is-posix-bracket": "0.1.1" } }, "expand-range": { "version": "1.8.2", "resolved": "https://registry.npmjs.org/expand-range/-/expand-range-1.8.2.tgz", "integrity": "sha1-opnv/TNf4nIeuujiV+x5ZE/IUzc=", "dev": true, "requires": { "fill-range": "2.2.4" } }, "external-editor": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-2.2.0.tgz", "integrity": "sha512-bSn6gvGxKt+b7+6TKEv1ZycHleA7aHhRHyAqJyp5pbUFuYYNIzpZnQDk7AsYckyWdEnTeAnay0aCy2aV6iTk9A==", "dev": true, "requires": { "chardet": "0.4.2", "iconv-lite": "0.4.24", "tmp": "0.0.33" } }, "extglob": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/extglob/-/extglob-0.3.2.tgz", "integrity": "sha1-Lhj/PS9JqydlzskCPwEdqo2DSaE=", "dev": true, "requires": { "is-extglob": "1.0.0" } }, "fast-deep-equal": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz", "integrity": "sha1-wFNHeBfIa1HaqFPIHgWbcz0CNhQ=", "dev": true }, "fast-json-stable-stringify": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=", "dev": true }, "fast-levenshtein": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", "dev": true }, "figures": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz", "integrity": "sha1-OrGi0qYsi/tDGgyUy3l6L84nyWI=", "dev": true, "requires": { "escape-string-regexp": "1.0.5" } }, "file-entry-cache": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-2.0.0.tgz", "integrity": "sha1-w5KZDD5oR4PYOLjISkXYoEhFg2E=", "dev": true, "requires": { "flat-cache": "1.3.4", "object-assign": "4.1.1" } }, "filename-regex": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/filename-regex/-/filename-regex-2.0.1.tgz", "integrity": "sha1-wcS5vuPglyXdsQa3XB4wH+LxiyY=", "dev": true }, "fill-range": { "version": "2.2.4", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-2.2.4.tgz", "integrity": "sha512-cnrcCbj01+j2gTG921VZPnHbjmdAf8oQV/iGeV2kZxGSyfYjjTyY79ErsK1WJWMpw6DaApEX72binqJE+/d+5Q==", "dev": true, "requires": { "is-number": "2.1.0", "isobject": "2.1.0", "randomatic": "3.1.0", "repeat-element": "1.1.3", "repeat-string": "1.6.1" } }, "flat-cache": { "version": "1.3.4", "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-1.3.4.tgz", "integrity": "sha512-VwyB3Lkgacfik2vhqR4uv2rvebqmDvFu4jlN/C1RzWoJEo8I7z4Q404oiqYCkq41mni8EzQnm95emU9seckwtg==", "dev": true, "requires": { "circular-json": "0.3.3", "graceful-fs": "4.2.0", "rimraf": "2.6.3", "write": "0.2.1" } }, "for-in": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz", "integrity": "sha1-gQaNKVqBQuwKxybG4iAMMPttXoA=", "dev": true }, "for-own": { "version": "0.1.5", "resolved": "https://registry.npmjs.org/for-own/-/for-own-0.1.5.tgz", "integrity": "sha1-UmXGgaTylNq78XyVCbZ2OqhFEM4=", "dev": true, "requires": { "for-in": "1.0.2" } }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "dev": true }, "functional-red-black-tree": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", "dev": true }, "glob": { "version": "7.1.4", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", "integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==", "dev": true, "requires": { "fs.realpath": "1.0.0", "inflight": "1.0.6", "inherits": "2.0.4", "minimatch": "3.0.4", "once": "1.4.0", "path-is-absolute": "1.0.1" } }, "glob-base": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/glob-base/-/glob-base-0.3.0.tgz", "integrity": "sha1-27Fk9iIbHAscz4Kuoyi0l98Oo8Q=", "dev": true, "requires": { "glob-parent": "2.0.0", "is-glob": "2.0.1" } }, "glob-parent": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-2.0.0.tgz", "integrity": "sha1-gTg9ctsFT8zPUzbaqQLxgvbtuyg=", "dev": true, "requires": { "is-glob": "2.0.1" } }, "globals": { "version": "11.12.0", "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", "dev": true }, "graceful-fs": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.0.tgz", "integrity": "sha512-jpSvDPV4Cq/bgtpndIWbI5hmYxhQGHPC4d4cqBPb4DLniCfhJokdXhwhaDuLBGLQdvvRum/UiX6ECVIPvDXqdg==", "dev": true }, "growl": { "version": "1.10.5", "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.5.tgz", "integrity": "sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==", "dev": true }, "has-ansi": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", "dev": true, "requires": { "ansi-regex": "2.1.1" }, "dependencies": { "ansi-regex": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", "dev": true } } }, "has-flag": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=" }, "he": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz", "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=", "dev": true }, "iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", "dev": true, "requires": { "safer-buffer": "2.1.2" } }, "ignore": { "version": "3.3.10", "resolved": "https://registry.npmjs.org/ignore/-/ignore-3.3.10.tgz", "integrity": "sha512-Pgs951kaMm5GXP7MOvxERINe3gsaVjUWFm+UZPSq9xYriQAksyhg0csnS0KXSNRD5NmNdapXEpjxG49+AKh/ug==", "dev": true }, "imurmurhash": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", "dev": true }, "inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", "dev": true, "requires": { "once": "1.4.0", "wrappy": "1.0.2" } }, "inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "dev": true }, "inquirer": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-3.3.0.tgz", "integrity": "sha512-h+xtnyk4EwKvFWHrUYsWErEVR+igKtLdchu+o0Z1RL7VU/jVMFbYir2bp6bAj8efFNxWqHX0dIss6fJQ+/+qeQ==", "dev": true, "requires": { "ansi-escapes": "3.2.0", "chalk": "2.4.2", "cli-cursor": "2.1.0", "cli-width": "2.2.0", "external-editor": "2.2.0", "figures": "2.0.0", "lodash": "4.17.11", "mute-stream": "0.0.7", "run-async": "2.3.0", "rx-lite": "4.0.8", "rx-lite-aggregates": "4.0.8", "string-width": "2.1.1", "strip-ansi": "4.0.0", "through": "2.3.8" } }, "is-buffer": { "version": "1.1.6", "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==", "dev": true }, "is-dotfile": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/is-dotfile/-/is-dotfile-1.0.3.tgz", "integrity": "sha1-pqLzL/0t+wT1yiXs0Pa4PPeYoeE=", "dev": true }, "is-equal-shallow": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/is-equal-shallow/-/is-equal-shallow-0.1.3.tgz", "integrity": "sha1-IjgJj8Ih3gvPpdnqxMRdY4qhxTQ=", "dev": true, "requires": { "is-primitive": "2.0.0" } }, "is-extendable": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/is-extendable/-/is-extendable-0.1.1.tgz", "integrity": "sha1-YrEQ4omkcUGOPsNqYX1HLjAd/Ik=", "dev": true }, "is-extglob": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-1.0.0.tgz", "integrity": "sha1-rEaBd8SUNAWgkvyPKXYMb/xiBsA=", "dev": true }, "is-fullwidth-code-point": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", "dev": true }, "is-glob": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-2.0.1.tgz", "integrity": "sha1-0Jb5JqPe1WAPP9/ZEZjLCIjC2GM=", "dev": true, "requires": { "is-extglob": "1.0.0" } }, "is-module": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-module/-/is-module-1.0.0.tgz", "integrity": "sha1-Mlj7afeMFNW4FdZkM2tM/7ZEFZE=", "dev": true }, "is-number": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-2.1.0.tgz", "integrity": "sha1-Afy7s5NGOlSPL0ZszhbezknbkI8=", "dev": true, "requires": { "kind-of": "3.2.2" } }, "is-posix-bracket": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/is-posix-bracket/-/is-posix-bracket-0.1.1.tgz", "integrity": "sha1-MzTceXdDaOkvAW5vvAqI9c1ua8Q=", "dev": true }, "is-primitive": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/is-primitive/-/is-primitive-2.0.0.tgz", "integrity": "sha1-IHurkWOEmcB7Kt8kCkGochADRXU=", "dev": true }, "is-promise": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz", "integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=", "dev": true }, "is-resolvable": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/is-resolvable/-/is-resolvable-1.1.0.tgz", "integrity": "sha512-qgDYXFSR5WvEfuS5dMj6oTMEbrrSaM0CrFk2Yiq/gXnBvD9pMa2jGXxyhGLfvhZpuMZe18CJpFxAt3CRs42NMg==", "dev": true }, "isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", "dev": true }, "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", "dev": true }, "isobject": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/isobject/-/isobject-2.1.0.tgz", "integrity": "sha1-8GVWEJaj8dou9GJy+BXIQNh+DIk=", "dev": true, "requires": { "isarray": "1.0.0" } }, "js-tokens": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=", "dev": true }, "js-yaml": { "version": "3.13.1", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", "integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==", "dev": true, "requires": { "argparse": "1.0.10", "esprima": "4.0.1" } }, "jsesc": { "version": "0.5.0", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz", "integrity": "sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0=" }, "json-schema-traverse": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz", "integrity": "sha1-NJptRMU6Ud6JtAgFxdXlm0F9M0A=", "dev": true }, "json-stable-stringify-without-jsonify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", "dev": true }, "kind-of": { "version": "3.2.2", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", "dev": true, "requires": { "is-buffer": "1.1.6" } }, "klaw": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/klaw/-/klaw-2.1.1.tgz", "integrity": "sha1-QrdolHARacyRD9DRnOZ3tfs3ivE=", "dev": true, "requires": { "graceful-fs": "4.2.0" } }, "levn": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", "integrity": "sha1-OwmSTt+fCDwEkP3UwLxEIeBHZO4=", "dev": true, "requires": { "prelude-ls": "1.1.2", "type-check": "0.3.2" } }, "lodash": { "version": "4.17.11", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", "dev": true }, "lru-cache": { "version": "4.1.5", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", "integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==", "dev": true, "requires": { "pseudomap": "1.0.2", "yallist": "2.1.2" } }, "magic-string": { "version": "0.25.3", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.3.tgz", "integrity": "sha512-6QK0OpF/phMz0Q2AxILkX2mFhi7m+WMwTRg0LQKq/WBB0cDP4rYH3Wp4/d3OTXlrPLVJT/RFqj8tFeAR4nk8AA==", "requires": { "sourcemap-codec": "1.4.4" } }, "math-random": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/math-random/-/math-random-1.0.1.tgz", "integrity": "sha1-izqsWIuKZuSXXjzepn97sylgH6w=", "dev": true }, "micromatch": { "version": "2.3.11", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-2.3.11.tgz", "integrity": "sha1-hmd8l9FyCzY0MdBNDRUpO9OMFWU=", "dev": true, "requires": { "arr-diff": "2.0.0", "array-unique": "0.2.1", "braces": "1.8.5", "expand-brackets": "0.1.5", "extglob": "0.3.2", "filename-regex": "2.0.1", "is-extglob": "1.0.0", "is-glob": "2.0.1", "kind-of": "3.2.2", "normalize-path": "2.1.1", "object.omit": "2.0.1", "parse-glob": "3.0.4", "regex-cache": "0.4.4" } }, "mimic-fn": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz", "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==", "dev": true }, "minimatch": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "dev": true, "requires": { "brace-expansion": "1.1.11" } }, "minimist": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" }, "mkdirp": { "version": "0.5.1", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "dev": true, "requires": { "minimist": "0.0.8" }, "dependencies": { "minimist": { "version": "0.0.8", "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", "dev": true } } }, "mocha": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/mocha/-/mocha-5.2.0.tgz", "integrity": "sha512-2IUgKDhc3J7Uug+FxMXuqIyYzH7gJjXECKe/w43IGgQHTSj3InJi+yAA7T24L9bQMRKiUEHxEX37G5JpVUGLcQ==", "dev": true, "requires": { "browser-stdout": "1.3.1", "commander": "2.15.1", "debug": "3.1.0", "diff": "3.5.0", "escape-string-regexp": "1.0.5", "glob": "7.1.2", "growl": "1.10.5", "he": "1.1.1", "minimatch": "3.0.4", "mkdirp": "0.5.1", "supports-color": "5.4.0" }, "dependencies": { "debug": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", "dev": true, "requires": { "ms": "2.0.0" } }, "glob": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", "dev": true, "requires": { "fs.realpath": "1.0.0", "inflight": "1.0.6", "inherits": "2.0.4", "minimatch": "3.0.4", "once": "1.4.0", "path-is-absolute": "1.0.1" } }, "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", "dev": true }, "supports-color": { "version": "5.4.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz", "integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==", "dev": true, "requires": { "has-flag": "3.0.0" } } } }, "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, "mute-stream": { "version": "0.0.7", "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz", "integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=", "dev": true }, "natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", "dev": true }, "normalize-path": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-2.1.1.tgz", "integrity": "sha1-GrKLVW4Zg2Oowab35vogE3/mrtk=", "dev": true, "requires": { "remove-trailing-separator": "1.1.0" } }, "object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", "dev": true }, "object.omit": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/object.omit/-/object.omit-2.0.1.tgz", "integrity": "sha1-Gpx0SCnznbuFjHbKNXmuKlTr0fo=", "dev": true, "requires": { "for-own": "0.1.5", "is-extendable": "0.1.1" } }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", "dev": true, "requires": { "wrappy": "1.0.2" } }, "onetime": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/onetime/-/onetime-2.0.1.tgz", "integrity": "sha1-BnQoIw/WdEOyeUsiu6UotoZ5YtQ=", "dev": true, "requires": { "mimic-fn": "1.2.0" } }, "optionator": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.2.tgz", "integrity": "sha1-NkxeQJ0/TWMB1sC0wFu6UBgK62Q=", "dev": true, "requires": { "deep-is": "0.1.3", "fast-levenshtein": "2.0.6", "levn": "0.3.0", "prelude-ls": "1.1.2", "type-check": "0.3.2", "wordwrap": "1.0.0" } }, "os-homedir": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-2.0.0.tgz", "integrity": "sha512-saRNz0DSC5C/I++gFIaJTXoFJMRwiP5zHar5vV3xQ2TkgEw6hDCcU5F272JjUylpiVgBrZNQHnfjkLabTfb92Q==" }, "os-tmpdir": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", "dev": true }, "parse-glob": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/parse-glob/-/parse-glob-3.0.4.tgz", "integrity": "sha1-ssN2z7EfNVE7rdFz7wu246OIORw=", "dev": true, "requires": { "glob-base": "0.3.0", "is-dotfile": "1.0.3", "is-extglob": "1.0.0", "is-glob": "2.0.1" } }, "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "dev": true }, "path-is-inside": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/path-is-inside/-/path-is-inside-1.0.2.tgz", "integrity": "sha1-NlQX3t5EQw0cEa9hAn+s8HS9/FM=", "dev": true }, "path-parse": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", "dev": true }, "pluralize": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/pluralize/-/pluralize-7.0.0.tgz", "integrity": "sha512-ARhBOdzS3e41FbkW/XWrTEtukqqLoK5+Z/4UeDaLuSW+39JPeFgs4gCGqsrJHVZX0fUrx//4OF0K1CUGwlIFow==", "dev": true }, "prelude-ls": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=", "dev": true }, "preserve": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/preserve/-/preserve-0.2.0.tgz", "integrity": "sha1-gV7R9uvGWSb4ZbMQwHE7yzMVzks=", "dev": true }, "process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", "dev": true }, "progress": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", "dev": true }, "pseudomap": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=", "dev": true }, "randomatic": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/randomatic/-/randomatic-3.1.0.tgz", "integrity": "sha512-KnGPVE0lo2WoXxIZ7cPR8YBpiol4gsSuOwDSg410oHh80ZMp5EiypNqL2K4Z77vJn6lB5rap7IkAmcUlalcnBQ==", "dev": true, "requires": { "is-number": "4.0.0", "kind-of": "6.0.2", "math-random": "1.0.1" }, "dependencies": { "is-number": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-4.0.0.tgz", "integrity": "sha512-rSklcAIlf1OmFdyAqbnWTLVelsQ58uvZ66S/ZyawjWqIviTWCjg2PzVGw8WUA+nNuPTqb4wgA+NszrJ+08LlgQ==", "dev": true }, "kind-of": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz", "integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==", "dev": true } } }, "readable-stream": { "version": "2.3.6", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "dev": true, "requires": { "core-util-is": "1.0.2", "inherits": "2.0.4", "isarray": "1.0.0", "process-nextick-args": "2.0.1", "safe-buffer": "5.1.2", "string_decoder": "1.1.1", "util-deprecate": "1.0.2" } }, "regenerate": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.0.tgz", "integrity": "sha512-1G6jJVDWrt0rK99kBjvEtziZNCICAuvIPkSiUFIQxVP06RCVpq3dmDo2oi6ABpYaDYaTRr67BEhL8r1wgEZZKg==" }, "regenerate-unicode-properties": { "version": "8.0.2", "resolved": "https://registry.npmjs.org/regenerate-unicode-properties/-/regenerate-unicode-properties-8.0.2.tgz", "integrity": "sha512-SbA/iNrBUf6Pv2zU8Ekv1Qbhv92yxL4hiDa2siuxs4KKn4oOoMDHXjAf7+Nz9qinUQ46B1LcWEi/PhJfPWpZWQ==", "requires": { "regenerate": "1.4.0" } }, "regex-cache": { "version": "0.4.4", "resolved": "https://registry.npmjs.org/regex-cache/-/regex-cache-0.4.4.tgz", "integrity": "sha512-nVIZwtCjkC9YgvWkpM55B5rBhBYRZhAaJbgcFYXXsHnbZ9UZI9nnVWYZpBlCqv9ho2eZryPnWrZGsOdPwVWXWQ==", "dev": true, "requires": { "is-equal-shallow": "0.1.3" } }, "regexpp": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-1.1.0.tgz", "integrity": "sha512-LOPw8FpgdQF9etWMaAfG/WRthIdXJGYp4mJ2Jgn/2lpkbod9jPn0t9UqN7AxBOKNfzRbYyVfgc7Vk4t/MpnXgw==", "dev": true }, "regexpu-core": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/regexpu-core/-/regexpu-core-4.5.4.tgz", "integrity": "sha512-BtizvGtFQKGPUcTy56o3nk1bGRp4SZOTYrDtGNlqCQufptV5IkkLN6Emw+yunAJjzf+C9FQFtvq7IoA3+oMYHQ==", "requires": { "regenerate": "1.4.0", "regenerate-unicode-properties": "8.0.2", "regjsgen": "0.5.0", "regjsparser": "0.6.0", "unicode-match-property-ecmascript": "1.0.4", "unicode-match-property-value-ecmascript": "1.1.0" } }, "regjsgen": { "version": "0.5.0", "resolved": "https://registry.npmjs.org/regjsgen/-/regjsgen-0.5.0.tgz", "integrity": "sha512-RnIrLhrXCX5ow/E5/Mh2O4e/oa1/jW0eaBKTSy3LaCj+M3Bqvm97GWDp2yUtzIs4LEn65zR2yiYGFqb2ApnzDA==" }, "regjsparser": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/regjsparser/-/regjsparser-0.6.0.tgz", "integrity": "sha512-RQ7YyokLiQBomUJuUG8iGVvkgOLxwyZM8k6d3q5SAXpg4r5TZJZigKFvC6PpD+qQ98bCDC5YelPeA3EucDoNeQ==", "requires": { "jsesc": "0.5.0" } }, "remove-trailing-separator": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz", "integrity": "sha1-wkvOKig62tW8P1jg1IJJuSN52O8=", "dev": true }, "repeat-element": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/repeat-element/-/repeat-element-1.1.3.tgz", "integrity": "sha512-ahGq0ZnV5m5XtZLMb+vP76kcAM5nkLqk0lpqAuojSKGgQtn4eRi4ZZGm2olo2zKFH+sMsWaqOCW1dqAnOru72g==", "dev": true }, "repeat-string": { "version": "1.6.1", "resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz", "integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc=", "dev": true }, "require-uncached": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/require-uncached/-/require-uncached-1.0.3.tgz", "integrity": "sha1-Tg1W1slmL9MeQwEcS5WqSZVUIdM=", "dev": true, "requires": { "caller-path": "0.1.0", "resolve-from": "1.0.1" } }, "resolve": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.8.1.tgz", "integrity": "sha512-AicPrAC7Qu1JxPCZ9ZgCZlY35QgFnNqc+0LtbRNxnVw4TXvjQ72wnuL9JQcEBgXkI9JM8MsT9kaQoHcpCRJOYA==", "dev": true, "requires": { "path-parse": "1.0.6" } }, "resolve-from": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-1.0.1.tgz", "integrity": "sha1-Jsv+k10a7uq7Kbw/5a6wHpPUQiY=", "dev": true }, "restore-cursor": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-2.0.0.tgz", "integrity": "sha1-n37ih/gv0ybU/RYpI9YhKe7g368=", "dev": true, "requires": { "onetime": "2.0.1", "signal-exit": "3.0.2" } }, "rimraf": { "version": "2.6.3", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", "dev": true, "requires": { "glob": "7.1.4" } }, "rollup": { "version": "0.66.0", "resolved": "https://registry.npmjs.org/rollup/-/rollup-0.66.0.tgz", "integrity": "sha512-WOkVBSdod3phCSAri5Q579JufeAzJTi43L4oAHzFtjRWJTv2LIszYCU3K9TLMEsVksMY93EwgWCb+hpKRhQwGg==", "dev": true, "requires": { "@types/estree": "0.0.39", "@types/node": "10.11.4" } }, "rollup-plugin-buble": { "version": "0.19.6", "resolved": "https://registry.npmjs.org/rollup-plugin-buble/-/rollup-plugin-buble-0.19.6.tgz", "integrity": "sha512-El5Fut4/wEO17ZN/n9BZvqd7DXXB2WbJr/DKvr89LXChC/cHllE0XwiUDeAalrTkgr0WrnyLDTCQvEv+cGywWQ==", "dev": true, "requires": { "buble": "0.19.6", "rollup-pluginutils": "2.3.3" } }, "rollup-plugin-commonjs": { "version": "9.1.8", "resolved": "https://registry.npmjs.org/rollup-plugin-commonjs/-/rollup-plugin-commonjs-9.1.8.tgz", "integrity": "sha512-c3nAfVVyEwbq9OohIeQudfQQdGV9Cl1RE8MUc90fH9UdtCiWAYpI+au3HxGwNf1DdV51HfBjCDbT4fwjsZEUUg==", "dev": true, "requires": { "estree-walker": "0.5.2", "magic-string": "0.22.5", "resolve": "1.8.1", "rollup-pluginutils": "2.3.3" }, "dependencies": { "magic-string": { "version": "0.22.5", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.22.5.tgz", "integrity": "sha512-oreip9rJZkzvA8Qzk9HFs8fZGF/u7H/gtrE8EN6RjKJ9kh2HlC+yQ2QezifqTZfGyiuAV0dRv5a+y/8gBb1m9w==", "dev": true, "requires": { "vlq": "0.2.3" } }, "vlq": { "version": "0.2.3", "resolved": "https://registry.npmjs.org/vlq/-/vlq-0.2.3.tgz", "integrity": "sha512-DRibZL6DsNhIgYQ+wNdWDL2SL3bKPlVrRiBqV5yuMm++op8W4kGFtaQfCs4KEJn0wBZcHVHJ3eoywX8983k1ow==", "dev": true } } }, "rollup-plugin-json": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/rollup-plugin-json/-/rollup-plugin-json-3.1.0.tgz", "integrity": "sha512-BlYk5VspvGpjz7lAwArVzBXR60JK+4EKtPkCHouAWg39obk9S61hZYJDBfMK+oitPdoe11i69TlxKlMQNFC/Uw==", "dev": true, "requires": { "rollup-pluginutils": "2.3.3" } }, "rollup-plugin-node-resolve": { "version": "3.4.0", "resolved": "https://registry.npmjs.org/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-3.4.0.tgz", "integrity": "sha512-PJcd85dxfSBWih84ozRtBkB731OjXk0KnzN0oGp7WOWcarAFkVa71cV5hTJg2qpVsV2U8EUwrzHP3tvy9vS3qg==", "dev": true, "requires": { "builtin-modules": "2.0.0", "is-module": "1.0.0", "resolve": "1.8.1" } }, "rollup-pluginutils": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.3.3.tgz", "integrity": "sha512-2XZwja7b6P5q4RZ5FhyX1+f46xi1Z3qBKigLRZ6VTZjwbN0K1IFGMlwm06Uu0Emcre2Z63l77nq/pzn+KxIEoA==", "dev": true, "requires": { "estree-walker": "0.5.2", "micromatch": "2.3.11" } }, "run-async": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.3.0.tgz", "integrity": "sha1-A3GrSuC91yDUFm19/aZP96RFpsA=", "dev": true, "requires": { "is-promise": "2.1.0" } }, "rx-lite": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/rx-lite/-/rx-lite-4.0.8.tgz", "integrity": "sha1-Cx4Rr4vESDbwSmQH6S2kJGe3lEQ=", "dev": true }, "rx-lite-aggregates": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/rx-lite-aggregates/-/rx-lite-aggregates-4.0.8.tgz", "integrity": "sha1-dTuHqJoRyVRnxKwWJsTvxOBcZ74=", "dev": true, "requires": { "rx-lite": "4.0.8" } }, "safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", "dev": true }, "safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "dev": true }, "semver": { "version": "5.7.0", "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==", "dev": true }, "shebang-command": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", "dev": true, "requires": { "shebang-regex": "1.0.0" } }, "shebang-regex": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=", "dev": true }, "signal-exit": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", "dev": true }, "slice-ansi": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-1.0.0.tgz", "integrity": "sha512-POqxBK6Lb3q6s047D/XsDVNPnF9Dl8JSaqe9h9lURl0OdNqy/ujDrOiIHtsqXMGbWWTIomRzAMaTyawAU//Reg==", "dev": true, "requires": { "is-fullwidth-code-point": "2.0.0" } }, "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", "dev": true }, "source-map-support": { "version": "0.5.12", "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.12.tgz", "integrity": "sha512-4h2Pbvyy15EE02G+JOZpUCmqWJuqrs+sEkzewTm++BPi7Hvn/HwcqLAcNxYAyI0x13CpPPn+kMjl+hplXMHITQ==", "dev": true, "requires": { "buffer-from": "1.1.1", "source-map": "0.6.1" } }, "sourcemap-codec": { "version": "1.4.4", "resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.4.tgz", "integrity": "sha512-CYAPYdBu34781kLHkaW3m6b/uUSyMOC2R61gcYMWooeuaGtjof86ZA/8T+qVPPt7np1085CR9hmMGrySwEc8Xg==" }, "sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", "dev": true }, "string-width": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", "dev": true, "requires": { "is-fullwidth-code-point": "2.0.0", "strip-ansi": "4.0.0" } }, "string_decoder": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", "dev": true, "requires": { "safe-buffer": "5.1.2" } }, "strip-ansi": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", "dev": true, "requires": { "ansi-regex": "3.0.0" } }, "strip-json-comments": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", "dev": true }, "supports-color": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", "requires": { "has-flag": "3.0.0" } }, "table": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/table/-/table-4.0.2.tgz", "integrity": "sha512-UUkEAPdSGxtRpiV9ozJ5cMTtYiqz7Ni1OGqLXRCynrvzdtR1p+cfOWe2RJLwvUG8hNanaSRjecIqwOjqeatDsA==", "dev": true, "requires": { "ajv": "5.5.2", "ajv-keywords": "2.1.1", "chalk": "2.4.2", "lodash": "4.17.11", "slice-ansi": "1.0.0", "string-width": "2.1.1" } }, "test262": { "version": "git+https://github.com/tc39/test262.git#4f1155c566a222238fd86f179c6635ecb4c289bb", "dev": true }, "test262-stream": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/test262-stream/-/test262-stream-1.3.0.tgz", "integrity": "sha512-TSv+Z4hftmRuUJVJk7kaguWLlVLRfwyWm1DOt4kvTXAanATxv6A1HhjRTrSBI00XXEWQ+cUdsDii8tn+fkjXyw==", "dev": true, "requires": { "js-yaml": "3.13.1", "klaw": "2.1.1" } }, "text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", "dev": true }, "through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", "dev": true }, "tmp": { "version": "0.0.33", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", "integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", "dev": true, "requires": { "os-tmpdir": "1.0.2" } }, "type-check": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", "integrity": "sha1-WITKtRLPHTVeP7eE8wgEsrUg23I=", "dev": true, "requires": { "prelude-ls": "1.1.2" } }, "typedarray": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", "dev": true }, "unicode-canonical-property-names-ecmascript": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz", "integrity": "sha512-jDrNnXWHd4oHiTZnx/ZG7gtUTVp+gCcTTKr8L0HjlwphROEW3+Him+IpvC+xcJEFegapiMZyZe02CyuOnRmbnQ==" }, "unicode-match-property-ecmascript": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/unicode-match-property-ecmascript/-/unicode-match-property-ecmascript-1.0.4.tgz", "integrity": "sha512-L4Qoh15vTfntsn4P1zqnHulG0LdXgjSO035fEpdtp6YxXhMT51Q6vgM5lYdG/5X3MjS+k/Y9Xw4SFCY9IkR0rg==", "requires": { "unicode-canonical-property-names-ecmascript": "1.0.4", "unicode-property-aliases-ecmascript": "1.0.5" } }, "unicode-match-property-value-ecmascript": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/unicode-match-property-value-ecmascript/-/unicode-match-property-value-ecmascript-1.1.0.tgz", "integrity": "sha512-hDTHvaBk3RmFzvSl0UVrUmC3PuW9wKVnpoUDYH0JDkSIovzw+J5viQmeYHxVSBptubnr7PbH2e0fnpDRQnQl5g==" }, "unicode-property-aliases-ecmascript": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/unicode-property-aliases-ecmascript/-/unicode-property-aliases-ecmascript-1.0.5.tgz", "integrity": "sha512-L5RAqCfXqAwR3RriF8pM0lU0w4Ryf/GgzONwi6KnL1taJQa7x1TCxdJnILX59WIGOwR57IVxn7Nej0fz1Ny6fw==" }, "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", "dev": true }, "vlq": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/vlq/-/vlq-1.0.0.tgz", "integrity": "sha512-o3WmXySo+oI5thgqr7Qy8uBkT/v9Zr+sRyrh1lr8aWPUkgDWdWt4Nae2WKBrLsocgE8BuWWD0jLc+VW8LeU+2g==", "dev": true }, "which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", "dev": true, "requires": { "isexe": "2.0.0" } }, "wordwrap": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", "integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=", "dev": true }, "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", "dev": true }, "write": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/write/-/write-0.2.1.tgz", "integrity": "sha1-X8A4KOJkzqP+kUVUdvejxWbLB1c=", "dev": true, "requires": { "mkdirp": "0.5.1" } }, "yallist": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=", "dev": true } } } buble-0.19.8/package.json000066400000000000000000000052401350705536200151770ustar00rootroot00000000000000{ "name": "buble", "version": "0.19.8", "description": "The blazing fast, batteries-included ES2015 compiler", "main": "dist/buble.cjs.js", "module": "dist/buble.es.js", "browser": { "dist/buble.cjs.js": "./dist/buble-browser.cjs.js", "dist/buble.es.js": "./dist/buble-browser.es.js" }, "unpkg": "dist/buble-browser-deps.umd.js", "files": [ "bin", "src", "dist", "register.js", "README.md" ], "scripts": { "build": "rollup -c", "test": "mocha test/test.js", "pretest": "npm run build", "test:register": "echo '\"use strict\";' | cat - src/program/Node.js | sed 's/export default/module.exports =/' | node -r ./register.js", "test:full": "npm run test && npm run test:register && npm run lint", "test:bundlers": "npm run test:bundlers:rollup && npm run test:bundlers:webpack && npm run test:bundlers:parcel", "test:bundlers:rollup": "test \"$(npx rollup -c test/bundlers/rollup.config.js | node)\" = 'var x = 4'", "test:bundlers:webpack": "cd test/bundlers && mkdir -p node_modules && npm i webpack && node webpack.js && test \"$(node dist/main.js)\" = 'var x = 4'", "test:bundlers:parcel": "cd test/bundlers && mkdir -p node_modules && npm i parcel && npx parcel build index.js --no-cache && test \"$(node dist/index.js)\" = 'var x = 4'", "prepublish": "npm test", "lint": "eslint bin/ src/ test/test.js test/utils/ register.js rollup.*.js scripts/" }, "bin": { "buble": "./bin/buble" }, "repository": { "type": "git", "url": "git+https://github.com/bublejs/buble.git" }, "keywords": [ "javascript", "transpilation", "compilation", "esnext", "es2015", "es2017", "es6", "es7" ], "author": "Rich Harris", "license": "MIT", "bugs": { "url": "https://github.com/bublejs/buble/issues" }, "homepage": "https://github.com/bublejs/buble#README", "devDependencies": { "console-group": "^0.3.3", "eslint": "^4.19.1", "glob": "^7.1.4", "mocha": "^5.2.0", "rimraf": "^2.6.3", "rollup": "0.66.0", "rollup-plugin-buble": "^0.19.6", "rollup-plugin-commonjs": "=9.1.8", "rollup-plugin-json": "^3.1.0", "rollup-plugin-node-resolve": "^3.4.0", "rollup-pluginutils": "2.3.3", "source-map": "^0.6.1", "source-map-support": "^0.5.12", "test262": "git+https://github.com/tc39/test262.git#4f1155c566a222238fd86f179c6635ecb4c289bb", "test262-stream": "^1.3.0" }, "dependencies": { "acorn": "^6.1.1", "acorn-dynamic-import": "^4.0.0", "acorn-jsx": "^5.0.1", "chalk": "^2.4.2", "magic-string": "^0.25.3", "minimist": "^1.2.0", "os-homedir": "^2.0.0", "regexpu-core": "^4.5.4" } } buble-0.19.8/register.js000066400000000000000000000043151350705536200150750ustar00rootroot00000000000000var fs = require('fs'); var path = require('path'); var crypto = require('crypto'); var homedir = require('os-homedir'); var buble = require('./'); var original = require.extensions[ '.js' ]; var nodeModulesPattern = path.sep === '/' ? /\/node_modules\// : /\\node_modules\\/; var nodeVersion = /(?:0\.)?\d+/.exec(process.version)[0]; var versions = [ '0.10', '0.12', '4', '5', '6' ]; if (!~versions.indexOf(nodeVersion)) { if (+nodeVersion > 6) { nodeVersion = '6'; } else { throw new Error('Unsupported version (' + nodeVersion + '). Please raise an issue at https://github.com/bublejs/buble/issues'); } } var options = { target: { node: nodeVersion } }; function mkdirp (dir) { var parent = path.dirname(dir); if (dir === parent) return; mkdirp(parent); try { fs.mkdirSync(dir); } catch (err) { if (err.code !== 'EEXIST') throw err; } } var home = homedir(); if (home) { var cachedir = path.join(home, '.buble-cache', String(nodeVersion)); mkdirp(cachedir); fs.writeFileSync(path.join(home, '.buble-cache/README.txt'), 'These files enable a faster startup when using buble/register. You can safely delete this folder at any time. See https://buble.surge.sh/guide/ for more information.'); } var optionsStringified = JSON.stringify(options); require.extensions[ '.js' ] = function (m, filename) { if (nodeModulesPattern.test(filename)) return original(m, filename); var source = fs.readFileSync(filename, 'utf-8'); var hash = crypto.createHash('sha256'); hash.update(buble.VERSION); hash.update(optionsStringified); hash.update(source); var key = hash.digest('hex') + '.json'; var cachepath = path.join(cachedir, key); var compiled; if (cachedir) { try { compiled = JSON.parse(fs.readFileSync(cachepath, 'utf-8')); } catch (err) { // noop } } if (!compiled) { try { compiled = buble.transform(source, options); if (cachedir) { fs.writeFileSync(cachepath, JSON.stringify(compiled)); } } catch (err) { if (err.snippet) { console.log('Error compiling ' + filename + ':\n---'); console.log(err.snippet); console.log(err.message); console.log(''); process.exit(1); } throw err; } } m._compile('"use strict";\n' + compiled.code, filename); }; buble-0.19.8/rollup.config.js000066400000000000000000000011701350705536200160260ustar00rootroot00000000000000import createConfig from './rollup.create-config'; import pkg from './package.json'; const configs = [ /* node ESM/CJS builds */ createConfig({ output: [ { format: 'es', file: pkg.module }, { format: 'cjs', file: pkg.main } ], }), /* browser ESM/CJS builds (for bundlers) */ createConfig({ browser: true, output: [ { format: 'es', file: pkg.browser[pkg.module] }, { format: 'cjs', file: pkg.browser[pkg.main] } ], }), /* UMD with bundled dependencies, ready for browsers */ createConfig({ browser: true, external: [], output: { format: 'umd', file: pkg.unpkg }, }), ]; export default configs; buble-0.19.8/rollup.create-config.js000066400000000000000000000022001350705536200172620ustar00rootroot00000000000000import buble from 'rollup-plugin-buble'; import json from 'rollup-plugin-json'; import resolve from 'rollup-plugin-node-resolve'; import commonjs from 'rollup-plugin-commonjs'; import pkg from './package.json'; const ensureArray = maybeArr => Array.isArray(maybeArr) ? maybeArr : [maybeArr]; const createConfig = (opts) => { opts = opts || {}; const browser = opts.browser || false; const external = opts.external || Object.keys(pkg.dependencies || {}); const output = ensureArray(opts.output); return { input: 'src/index.js', output: output.map(format => Object.assign({}, format, { name: 'buble', sourcemap: true })), external: external, plugins: [ json(), commonjs({ extensions: ['.js', '.mjs'] }), buble({ target: !browser ? { node: 4 } : null, include: [ 'src/**', // For unpkg build 'node_modules/acorn-jsx/**', 'node_modules/regexpu-core/**', 'node_modules/unicode-match-property-ecmascript/**', 'node_modules/unicode-match-property-value-ecmascript/**', ], transforms: { dangerousForOf: true } }), resolve() ], }; }; export default createConfig; buble-0.19.8/scripts/000077500000000000000000000000001350705536200143775ustar00rootroot00000000000000buble-0.19.8/scripts/.eslintrc.yaml000066400000000000000000000001431350705536200171620ustar00rootroot00000000000000--- rules: no-empty: - "error" - { allowEmptyCatch: true } no-console: "off" buble-0.19.8/scripts/run_test262.js000066400000000000000000000170171350705536200170400ustar00rootroot00000000000000"use strict"; /** Run buble on test262 and execute the result S1: Wrong behavior of transpiled code S2: Transpiled code throws an error at runtime S3: Transpiling throws an unexpected error S4: this is a known, documented issue skip: These tests don't say anything interesting pass: transpiled code behaves correctly */ // FIXME: Check that expectations match at least one file const fs = require("fs"); const path = require("path"); const vm = require('vm'); const TestStream = require('test262-stream'); const parse = require("acorn").parse; const data = require('./test262-data.js'); const features_list = data.features_list; const file_list = data.file_list; const transform = require("..").transform; const verbose = process.argv[2] == "-v"; const nodeVersion = Number(process.version.match(/^v(\d+)\./)[1]); const acornWhitelist = fs.readFileSync(__dirname + "/test262-acorn.whitelist", "utf8").split("\n").filter(i => i.match(/ \(strict mode\)$/)).map(i => i.substr(0, i.length-(" (strict mode)".length))); const endOfAssertJs = "message += 'Expected a ' + expectedErrorConstructor.name + ' to be thrown but no exception was thrown at all';\n $ERROR(message);\n};"; const useStrict = '"use strict";\n'; process.on("unhandledRejection", (e) => { e && console.warn(e); }); const exec = (harness, text, filename, async) => { return new Promise((resolve, reject) => { try { vm.runInNewContext(`${useStrict} var $262 = { destroy() {}, createRealm() { return { global: global }; } }; ${harness} ${async ? "$DONE = _SANDBOX_DONE" : ""} ${text}`, { global, _SANDBOX_DONE: e => e ? reject(e) : resolve() }, {timeout: 1000, filename} ); if (!async) resolve(); } catch (e) { reject(e); } }); }; const runTest = (content, harness, report, filename, async, config) => { // If it is valid ES3 code, we don't need to transpile. // import.meta and dynamic import() is valid ES3, though. if (verbose) process.stdout.write("es3 ... "); if (!content.match(/import/)) { try { parse(content, {ecmaVersion: 3}); return Promise.resolve({skip: "validEs3"}); } catch (e) {} } if (verbose) process.stdout.write("transpile ... "); // Transpile let transformed; try { transformed = transform(content, { transforms: Object.assign({ dangerousForOf: true, dangerousTaggedTemplateString: true }, (config || {}).transforms), objectAssign: "Object.assign" }).code; } catch (e) { if (e.message.match(/is not implemented./)) return report(4, e); return report(3, e); } if (verbose) process.stdout.write("es5 ... "); // Make sure transpiled code is valid ES5 try { parse(transformed, {ecmaVersion: 5}); } catch (e) { return report(2, e); } return exec(harness, transformed, filename, async).then( () => ({pass: "true"}), e => report(1, e) ); }; let failed = false; const fail = (test, msg) => { console.warn(`${test.file}${test.attrs.features ? (' (' + test.attrs.features.join(', ') + ')') : ''}: ${msg}`); failed = true; }; const report = (test, expectedS) => (s, e, details) => { if (!expectedS) fail(test, `Unexpected S${s}: ${e}`); return Promise.resolve({fail: `s${s}${details ? "_" + details : ""}`}); }; const handle = test => { //////////////////////////// // Check skip and prepare // //////////////////////////// const skip = m => Promise.resolve(`skip_${m}`); if (test.attrs.negative && (test.attrs.negative.phase === "parse" || test.attrs.negative.phase === "early")) { return skip("testsParseError"); } if (test.attrs.negative && test.attrs.negative.phase === "runtime") { // FIXME: This should be doable return skip("testsRuntimeError"); } test.file = test.file.substr(5); // Strip leading 'test/' for (const item of data.skip_list) if (test.file.match(item.pattern)) return skip(item.desc); if ([ "built-ins/Date/parse/time-value-maximum-range.js", ].indexOf(test.file) > -1) { return skip("testsRunTimeBehaviourOnly"); } if (acornWhitelist.indexOf(test) > -1) { return skip("acornWhitelist"); } if ([ "built-ins/TypedArrayConstructors/ctors/typedarray-arg/other-ctor-buffer-ctor-species-not-ctor-throws.js", "language/global-code/decl-lex.js", "language/module-code/instn-local-bndng-const.js" ].indexOf(test.file) > -1 || test.file.endsWith("put-const.js") || test.file.indexOf("const-invalid-assignment") > -1) { // test bug: buble performs runtime const check at compile time return skip("constCheck"); } let harness = ''; if (!test.attrs.flags.raw) { if (test.contents.substr(0, useStrict.length) !== useStrict) { return skip("noStrict"); } const m = test.contents.indexOf(endOfAssertJs) + endOfAssertJs.length; harness = test.contents.substr(0, m); test.contents = test.contents.substr(m); } if (test.contents.match(/(eval(Script)?[()])|(Function\(")/)) { return skip("eval"); } //////////////////////// // Check expectations // //////////////////////// const expecteds = [{s: 0}]; const expect = (s, tag, config) => { if (config) expecteds.push({s, tag, config}); else if (s > expecteds[0].s) expecteds[0] = {s, tag}; }; if ((nodeVersion === 4 && test.file === "built-ins/TypedArrayConstructors/of/this-is-not-constructor.js")) { expect(1, "node4Bug"); } if (test.file === "language/statements/class/subclass/builtin-objects/Proxy/no-prototype-throws.js" && nodeVersion === 6) { return skip("node6Bug"); } // FIXME: S4 tests could also disable that specific transform if (test.attrs.features) for (const feature of test.attrs.features) if (features_list[feature]) expect.apply(null, features_list[feature]); for (const item of file_list) if (test.file.match(item.pattern)) expect(item.level, item.desc, item.config); // regExpUtils.js contains destructured arguments if ((test.attrs.includes || []).indexOf("regExpUtils.js") > -1) { harness = transform(harness, { transforms: { dangerousForOf: true } }).code; } ////////////// // Run test // ////////////// let ret = Promise.resolve(); for (let i = 0; i < expecteds.length; ++i) { const expected = expecteds[i]; ret = ret.then(() => runTest(test.contents, harness, report(test, expected.s), test.file, test.attrs.flags.async, expected.config)) .then(result => { if (expected.s) { const expectedString = `s${expected.s}_${expected.tag}`; if (result.skip === "nodeBug" && expected.s > 1) { fail(test, `Could not verify ${expectedString} due to skip_${result.skip}`); } else if (!result.skip) { if (!result.fail || result.fail !== "s" + expected.s && !((expected.s == 3 || expected.s == 4) && (result.fail == "s3" || result.fail == "s4"))) { fail(test, `Expected ${expectedString}, but got ${JSON.stringify(result)}`); } else { result.fail = expectedString; } } } return result.skip ? "skip_" + result.skip : (result.pass ? "pass_" + result.pass : "fail_" + result.fail); }); } return ret; }; const testDir = path.dirname(require.resolve("test262/package.json")); const stream = new TestStream(testDir); const counts = {}; let last = Promise.resolve(); stream.on('data', test => last = last.then(() => { if (verbose) process.stdout.write(`${test.file}${test.attrs.features ? ' (' + test.attrs.features.join(', ') + ')' : ''} ... `); return handle(test).then(result => { if (verbose) process.stdout.write(`${result}\n`); counts[result] = (counts[result] || 0) + 1; }); })); stream.on('end', () => { const sorted_counts = Object.keys(counts).sort((a, b) => counts[b] - counts[a] || (b < a ? 1 : -1)).map(k => [k, counts[k]]); sorted_counts.forEach(v => console.log(v[0] + ": " + v[1])); process.exit(failed ? 1 : 0); }); buble-0.19.8/scripts/test262-acorn.whitelist000066400000000000000000000000011350705536200206350ustar00rootroot00000000000000 buble-0.19.8/scripts/test262-data.js000066400000000000000000001647651350705536200171000ustar00rootroot00000000000000exports.features_list = { //generators: [4, "generators"], // test262 features acorn doesn't parse and thus are S3 "class-fields-private": [3, "unsupportedFeatures"], "class-fields-public": [3, "unsupportedFeatures"], "class-methods-private": [3, "unsupportedFeatures"], "class-static-fields-private": [3, "unsupportedFeatures"], "class-static-fields-public": [3, "unsupportedFeatures"], "class-static-methods-private": [3, "unsupportedFeatures"], "numeric-separator-literal": [3, "unsupportedFeatures"], // This is actually something bublé cannot handle, even though acorn parses it "optional-catch-binding": [3, "unsupportedFeatures"], "dynamic-import": [4, "importReserved"], "import.meta": [3, "importMeta"], // test262 features bublé doesn't transpile and thus are S2 // buble bug: Does not transpile new.target "new.target": [2, "newTarget"], "regexp-lookbehind": [2, "notTranspiledFeatures"], }; const mapFilePatterns = files => { const patterns = files.map(p => p.replace(/[-.,$]/g, '\\$&').replace(/\*/g, '.+')); return new RegExp("^(" + patterns.join("|") + ')$'); }; exports.file_list = [ // buble bug: dangerousTaggedTemplateLiteral { level: 1, desc: "dangerousTaggedTemplateLiteral", files: [ "language/expressions/(template-literal/tv-*|tagged-template/(template-object-frozen-strict.js|template-object.js|invalid-escape-sequences.js))", "built-ins/String/raw/(return-the-string-value-from-template|special-characters|template-substitutions-are-appended-on-same-index|zero-literal-segments).js" ]}, // Acorn doesn't parse BigInt without acorn-bigint { level: 3, desc: "BigInt", files: [ "built-ins/BigInt/as(Ui|I)ntN/(a|bits|l|n|o)*", "built-ins/BigInt/as(Ui|I)ntN/bigint-tobigint.js", "built-ins/BigInt/as(Ui|I)ntN/bigint-tobigint-toprimitive.js", "built-ins/BigInt/as(Ui|I)ntN/bigint-tobigint-wrapped-values.js", "built-ins/BigInt/(c|i|l|n|p|t|v)*", "built-ins/JSON/stringify/bigint(|-order|-replacer|-tojson).js", "built-ins/Number/bigint-conversion.js", "built-ins/Object/bigint.js", "built-ins/Object/prototype/toString/Object.prototype.toString.call-bigint.js", "built-ins/Object/setPrototypeOf/bigint.js", "built-ins/String/prototype/indexOf/position-tointeger-bigint.js", "built-ins/String/prototype/indexOf/searchstring-tostring-bigint.js", "built-ins/TypedArrayConstructors/BigInt/*", "built-ins/TypedArrayConstructors/(i|o|p)*(BigInt|bigint)*", "built-ins/TypedArray/prototype/*/BigInt/*", "built-ins/TypedArray/prototype/set/src-typedarray-big-throws.js", "language/*bigint*", ]}, // These have an u flag, so regexpucore throws { level: 3, desc: "regexpNamedGroups", files: [ "built-ins/RegExp/named-groups/(groups-p*.js|l*|unicode-(p*|r*))", ]}, // These don't have an u flag, so regexpucore is not executed on them { level: 2, desc: "regexpNamedGroups", files: [ "annexB/built-ins/RegExp/named-groups/non-unicode-malformed.js", "built-ins/RegExp/named-groups/groups-object-unmatched.js", "built-ins/RegExp/named-groups/groups-object.js", "built-ins/RegExp/named-groups/non-unicode-match.js", "built-ins/RegExp/named-groups/non-unicode-property-names.js", "built-ins/RegExp/named-groups/non-unicode-references.js", "language/literals/regexp/named-groups/forward-reference.js", ]}, { level: 3, desc: "regjsparserBug", files: [ "built-ins/RegExp/named-groups/unicode-property-names.js", ]}, { level: 1, desc: "regexpucoreBug", files: [ "built-ins/RegExp/property-escapes/generated/Case_Ignorable.js", "built-ins/RegExp/property-escapes/generated/Changes_When_NFKC_Casefolded.js", "built-ins/RegExp/property-escapes/generated/Changes_When_Titlecased.js", "built-ins/RegExp/property-escapes/generated/Changes_When_Uppercased.js", "built-ins/RegExp/property-escapes/generated/General_Category_-_Decimal_Number.js", "built-ins/RegExp/property-escapes/generated/General_Category_-_Lowercase_Letter.js", "built-ins/RegExp/property-escapes/generated/General_Category_-_Number.js", "built-ins/RegExp/property-escapes/generated/General_Category_-_Other.js", "built-ins/RegExp/property-escapes/generated/General_Category_-_Unassigned.js", "built-ins/RegExp/property-escapes/generated/Grapheme_Base.js", "built-ins/RegExp/property-escapes/generated/ID_Continue.js", "built-ins/RegExp/property-escapes/generated/Lowercase.js", "built-ins/RegExp/property-escapes/generated/XID_Continue.js", ]}, // buble bug: Since we parse with module source type, this does not parse // https://tc39.github.io/ecma262/#sec-identifiers-static-semantics-early-errors { level: 3, desc: "awaitKeyword", files: [ 'language/expressions/await/await-BindingIdentifier-in-global.js', 'language/expressions/await/await-in-generator.js', 'language/expressions/await/await-in-nested-function.js', 'language/expressions/await/await-in-nested-generator.js', "language/expressions/class/class-name-ident-await-escaped.js", "language/expressions/class/class-name-ident-await.js", "language/expressions/dynamic-import/assignment-expression/await-identifier.js", "language/statements/class/class-name-ident-await-escaped.js", "language/statements/class/class-name-ident-await.js", ]}, // Another valid script, invalid module (see also above) { level: 3, desc: "scriptInvalidModule", files: [ "*eval-script-code-host-resolves-module-code*", "*script-code-valid*", ]}, { level: 4, desc: "asyncFunction", files: [ "*await*", "*AsyncFunction*", "*async-(gen|meth|super|function|await)*", "language/expressions/async-arrow-function/(ar|aw|d|e|p|r|t)*", "built-ins/Function/prototype/toString/async-arrow-function.js", "*returns-promise.js", ]}, // buble bug: buble throws an error { level: 3, desc: "bubleThrowsError", files: [ "*ary-ptrn-elem-ary-empty-iter*", "*-object-patterns.js" ]}, // buble bug: Shouldn't trigger setters on a classes superclass { level: 1, desc: "superclassSetter", files: [ "*method-override.js", "language/statements/class/definition/side-effects-in-property-define.js", "language/statements/class/subclass/superclass-prototype-setter-constructor.js", ]}, // buble bug: The unicode property is not set for transpiled unicode regexps { level: 1, desc: "unicodeFlag", files: [ "built-ins/RegExp/prototype/unicode/this-val-regexp.js" ]}, // buble bug: buble emits invalid code { level: 2, desc: "badArrowTranspiling", files: [ "language/expressions/assignment/dstr/array-elem-init-fn-name-arrow.js", "language/expressions/assignment/dstr/obj-prop-elem-init-fn-name-arrow.js", "language/expressions/assignment/dstr/obj-id-init-fn-name-arrow.js", ]}, // buble bug: buble emits invalid code { level: 2, desc: "badAnonymousClassTranspiling", files: [ "language/expressions/object/fn-name-class.js", ]}, // buble bug: name for (arrow) function expressions wrong { level: 1, desc: "functionName", files: [ "language/statements/for/dstr/const-ary-ptrn-elem-id-init-fn-name-arrow.js", "language/statements/for/dstr/const-obj-ptrn-id-init-fn-name-arrow.js", "language/statements/for/dstr/const-obj-ptrn-id-init-fn-name-cover.js", "language/statements/for/dstr/const-obj-ptrn-id-init-fn-name-fn.js", "language/statements/for/dstr/let-ary-ptrn-elem-id-init-fn-name-arrow.js", "language/statements/for/dstr/let-obj-ptrn-id-init-fn-name-arrow.js", "language/statements/for/dstr/let-obj-ptrn-id-init-fn-name-cover.js", "language/statements/for/dstr/let-obj-ptrn-id-init-fn-name-fn.js", "language/statements/for/dstr/var-ary-ptrn-elem-id-init-fn-name-arrow.js", "language/statements/for/dstr/var-ary-ptrn-elem-id-init-fn-name-cover.js", "language/statements/for/dstr/var-ary-ptrn-elem-id-init-fn-name-fn.js", "language/statements/for/dstr/var-obj-ptrn-id-init-fn-name-arrow.js", "language/statements/for/dstr/var-obj-ptrn-id-init-fn-name-cover.js", "language/statements/for/dstr/var-obj-ptrn-id-init-fn-name-fn.js", "language/statements/for-of/dstr/array-elem-init-fn-name-arrow.js", "language/statements/for-of/dstr/array-elem-init-fn-name-cover.js", "language/statements/for-of/dstr/array-elem-init-fn-name-fn.js", "language/statements/for-of/dstr/obj-id-init-fn-name-arrow.js", "language/statements/for-of/dstr/obj-id-init-fn-name-cover.js", "language/statements/for-of/dstr/obj-id-init-fn-name-fn.js", "language/statements/for-of/dstr/obj-prop-elem-init-fn-name-arrow.js", "language/statements/for-of/dstr/obj-prop-elem-init-fn-name-cover.js", "language/statements/for-of/dstr/obj-prop-elem-init-fn-name-fn.js", "language/expressions/assignment/dstr/obj-prop-elem-init-fn-name-cover.js", "language/expressions/assignment/dstr/obj-prop-elem-init-fn-name-fn.js", "language/expressions/assignment/dstr/obj-id-init-fn-name-cover.js", "language/expressions/assignment/dstr/obj-id-init-fn-name-fn.js", "language/expressions/assignment/dstr/array-elem-init-fn-name-cover.js", "language/expressions/assignment/dstr/array-elem-init-fn-name-fn.js", "language/expressions/class/name.js", ]}, // buble bug: https://github.com/bublejs/buble/issues/77 { level: 2, desc: "classHeritage", files: [ "built-ins/Function/prototype/toString/class-declaration-complex-heritage.js" ]}, // buble bug: toString of classes, arrow functions and functions with argument defaults // is altered { level: 1, desc: "functionToString", files: [ "built-ins/Function/prototype/toString/class-declaration-complex-heritage.js", "built-ins/Function/prototype/toString/class-declaration-explicit-ctor.js", "built-ins/Function/prototype/toString/class-declaration-implicit-ctor.js", "built-ins/Function/prototype/toString/class-expression-explicit-ctor.js", "built-ins/Function/prototype/toString/class-expression-implicit-ctor.js", "built-ins/Function/prototype/toString/arrow-function.js", "built-ins/Function/prototype/toString/function-declaration-non-simple-parameter-list.js", "built-ins/Function/prototype/toString/method-*", ]}, // buble bug: class methods should not be enumerable on the prototype { level: 1, desc: "nonEnumerablePrototypeProperties", files: [ "language/computed-property-names/to-name-side-effects/class.js", "language/computed-property-names/to-name-side-effects/numbers-class.js" ]}, // buble bug: destructuring null or undefined should fail { level: 1, desc: "destructuringNullOrUndefined", files: [ "language/destructuring/binding/initialization-requires-object-coercible-null.js", "language/destructuring/binding/initialization-requires-object-coercible-undefined.js", "*obj-init-null.js", "*obj-init-undefined.js" ]}, // buble bug: template cache is keyed based on raw string literal { level: 1, desc: "templateCacheUnicodeEscape", files: [ "language/expressions/tagged-template/cache-differing-raw-strings.js" ]}, // buble bug: buble allows referencing later and self arguments in default values { level: 1, desc: "badParamsDefault", files: [ "*dflt-params-ref-(later|self).js" ]}, // buble bug: buble does not correctly set arguments count with default parameter { level: 1, desc: "fnLengthDefaultParams", files: [ "*dflt-params-trailing-comma.js", "*length-dflt.js" ]}, // buble bug: Shouldn't be able to call super() outside of constructor { level: 1, desc: "superConstructor", files: [ "language/expressions/arrow-function/lexical-super-call-from-within-constructor.js", ]}, { level: 1, desc: "computedProto", files: [ // buble bug: A computed property called "__proto__" does not set the prototype // This is probably not transpilable "language/expressions/object/computed-__proto__.js", // Duplicate property legal if computed "annexB/language/expressions/object/__proto__-duplicate-computed.js", ]}, // buble bug: Having a setter or getter with the same name // as an earlier property apparently used to be illegal { level: 2, desc: "setterGetterAfterProperty", files: [ "*prop-dup*" ]}, // buble bug: Various bugs around super { level: 1, desc: "superVarious", files: [ "language/statements/class/definition/this-check-ordering.js", "language/statements/class/definition/this-access-restriction.js", "language/statements/class/definition/this-access-restriction-2.js", "language/statements/class/super/in-constructor-superproperty-evaluation.js", "built-ins/Function/internals/Construct/derived-this-uninitialized.js", "language/expressions/delete/super-property.js", // delete super.xx "language/expressions/super/call-bind-this-value-twice.js", "language/expressions/super/call-bind-this-value.js", "language/expressions/super/call-proto-not-ctor.js", "language/expressions/super/prop-dot-cls-ref-this.js", "language/expressions/super/prop-dot-cls-this-uninit.js", "language/expressions/super/prop-expr-cls-ref-this.js", "language/expressions/super/prop-expr-cls-this-uninit.js", ]}, // buble does not support super outside of class methods { level: 3, desc: "superOutsideClass", files: [ 'language/expressions/object/getter-super-prop.js', 'language/expressions/object/method.js', 'language/expressions/object/setter-super-prop.js', 'language/expressions/super/prop-dot-cls-ref-strict.js', 'language/expressions/super/prop-dot-obj-null-proto.js', 'language/expressions/super/prop-dot-obj-ref-strict.js', 'language/expressions/super/prop-dot-obj-ref-this.js', 'language/expressions/super/prop-dot-obj-val-from-arrow.js', 'language/expressions/super/prop-dot-obj-val.js', 'language/expressions/super/prop-expr-cls-err.js', 'language/expressions/super/prop-expr-cls-key-err.js', 'language/expressions/super/prop-expr-cls-ref-strict.js', 'language/expressions/super/prop-expr-cls-unresolvable.js', 'language/expressions/super/prop-expr-obj-err.js', 'language/expressions/super/prop-expr-obj-key-err.js', 'language/expressions/super/prop-expr-obj-null-proto.js', 'language/expressions/super/prop-expr-obj-ref-strict.js', 'language/expressions/super/prop-expr-obj-ref-this.js', 'language/expressions/super/prop-expr-obj-unresolvable.js', 'language/expressions/super/prop-expr-obj-val-from-arrow.js', 'language/expressions/super/prop-expr-obj-val.js', 'language/computed-property-names/object/accessor/getter-super.js', 'language/computed-property-names/object/accessor/setter-super.js', 'language/computed-property-names/object/method/super.js', 'language/expressions/object/method-definition/name-super-prop-body.js', 'language/expressions/object/method-definition/name-super-prop-param.js', 'language/statements/class/syntax/class-body-method-definition-super-property.js', 'language/expressions/object/method-definition/async-super-call-body.js', 'language/expressions/object/method-definition/async-super-call-param.js', ]}, // buble bug: Various bugs around methods { level: 1, desc: "methodsVarious", files: [ "language/statements/class/definition/setters-prop-desc.js", "language/statements/class/definition/prototype-property.js", "language/statements/class/definition/methods.js", "language/statements/class/definition/getters-prop-desc.js", "language/statements/class/definition/accessors.js", "language/expressions/object/method-definition/name-prototype-prop.js", "language/expressions/object/method-definition/name-invoke-ctor.js", "language/computed-property-names/class/static/method-prototype.js", "language/statements/class/static-method-non-configurable-err.js", // class methods in Object.keys "language/computed-property-names/class/static/method-symbol.js", "language/computed-property-names/class/static/method-string.js", "language/computed-property-names/class/static/method-number.js", "language/computed-property-names/class/method/symbol.js", "language/computed-property-names/class/method/string.js", "language/computed-property-names/class/method/number.js", ]}, // buble bug: https://github.com/bublejs/buble/issues/69 { level: 2, desc: "computedGetterSetter", files: [ "*object/accessor-name-*", "built-ins/Function/prototype/toString/getter-object.js", "built-ins/Function/prototype/toString/setter-object.js", "built-ins/Object/fromEntries/uses-keys-not-iterator.js", "built-ins/RegExp/prototype/Symbol.matchAll/isregexp-called-once.js", "built-ins/RegExp/prototype/Symbol.matchAll/isregexp-this-throws.js", "built-ins/RegExp/prototype/Symbol.matchAll/species-constructor-get-species-throws.js", "built-ins/String/prototype/trimEnd/this-value-object-toprimitive-meth-priority.js", "built-ins/String/prototype/trimEnd/this-value-object-tostring-meth-priority.js", "built-ins/String/prototype/trimEnd/this-value-object-valueof-meth-priority.js", "built-ins/String/prototype/trimStart/this-value-object-toprimitive-meth-priority.js", "built-ins/String/prototype/trimStart/this-value-object-tostring-meth-priority.js", "built-ins/String/prototype/trimStart/this-value-object-valueof-meth-priority.js", "language/computed-property-names/object/accessor/getter-duplicates.js", "language/computed-property-names/object/accessor/getter.js", "language/computed-property-names/object/accessor/setter-duplicates.js", "language/computed-property-names/object/accessor/setter.js", "language/expressions/object/accessor-name-literal-string-empty.js", "language/expressions/object/fn-name-accessor-get.js", "language/expressions/object/fn-name-accessor-set.js", ]}, // Computed accessors in classes at least throw an error on transformation { level: 3, desc: "computedGetterSetterClass", files: [ "*class/accessor-name-*", "built-ins/Function/prototype/toString/getter-class-expression-static.js", "built-ins/Function/prototype/toString/getter-class-expression.js", "built-ins/Function/prototype/toString/getter-class-statement-static.js", "built-ins/Function/prototype/toString/getter-class-statement.js", "built-ins/Function/prototype/toString/setter-class-expression-static.js", "built-ins/Function/prototype/toString/setter-class-expression.js", "built-ins/Function/prototype/toString/setter-class-statement-static.js", "built-ins/Function/prototype/toString/setter-class-statement.js", "built-ins/Promise/prototype/finally/species-symbol.js", "built-ins/Promise/prototype/finally/subclass-species-constructor-(reject|resolve)-count.js", "language/computed-property-names/class/accessor/getter-duplicates.js", "language/computed-property-names/class/accessor/getter.js", "language/computed-property-names/class/accessor/setter-duplicates.js", "language/computed-property-names/class/accessor/setter.js", "language/computed-property-names/class/method/constructor-can-be-(g|s)etter.js", "language/computed-property-names/class/static/(g|s)etter-(constructor|prototype).js", "language/statements/class/definition/getters-non-configurable-err.js", "language/statements/class/definition/fn-name-accessor-get.js", "language/statements/class/definition/fn-name-accessor-set.js", "language/statements/class/definition/numeric-property-names.js", "language/statements/class/definition/setters-non-configurable-err.js", ]}, // buble bug: get/set after computed? { level: 2, desc: "getterSetterAfterComputed", files: [ "built-ins/String/prototype/trimStart/this-value-object-tostring-call-err.js", "built-ins/String/prototype/trimStart/this-value-object-valueof-call-err.js", "built-ins/String/prototype/trimStart/this-value-object-toprimitive-call-err.js", "built-ins/String/prototype/trimEnd/this-value-object-tostring-call-err.js", "built-ins/String/prototype/trimEnd/this-value-object-valueof-call-err.js", "built-ins/String/prototype/trimEnd/this-value-object-toprimitive-call-err.js", "language/expressions/object/__proto__-permitted-dup.js", ]}, // buble bug: Method with symbol as key has no name { level: 1, desc: "methodSymbolName", files: [ "language/statements/class/definition/fn-name-method.js", "language/expressions/object/method-definition/name-name-prop-symbol.js", "language/expressions/object/method-definition/fn-name-fn.js", "language/expressions/object/fn-name-arrow.js", "language/expressions/object/fn-name-cover.js", "language/expressions/object/fn-name-fn.js", ]}, // buble bug: Transpiled default value function access function body's scope { level: 1, desc: "defaultValueScope", files: [ "*paramsbody-var-open.js" ]}, // buble bug: transpiled arrow functions have a prototype { level: 1, desc: "arrowPrototype", files: [ "language/expressions/arrow-function/prototype-rules.js", ]}, // buble bug: transpiled arrow functions allow new { level: 1, desc: "arrowNew", files: [ "language/expressions/arrow-function/throw-new.js", ]}, // buble bug: dotAll is not supported { level: 2, desc: "dotAll", files: [ "built-ins/RegExp/dotall/with-dotall-unicode.js", "built-ins/RegExp/dotall/with-dotall.js", "built-ins/RegExp/prototype/dotAll/this-val-regexp.js", "built-ins/RegExp/prototype/flags/this-val-regexp.js", ]}, // buble bug: rest and spread properties executes getters instead of copying them { level: 1, desc: "restSpreadGetters", files: [ // Object.assign "*spread-obj-getter-init.js", // rest "language/expressions/assignment/dstr/obj-rest-order.js", ]}, // buble bug: characters which are valid in template literal but not string literal need to be transpiled { level: 2, desc: "templateLiteralLineContinuationAndTerminator", files: [ "language/expressions/template-literal/tv-line-terminator-sequence.js", ]}, // buble bug: Does not transpile unicode escapes // https://github.com/bublejs/buble/issues/75 { level: 2, desc: "unicodeCodePointEscapes", files: [ "*escape-hex.js", "annexB/built-ins/escape/escape-above-astral.js", "built-ins/RegExp/dotall/without-dotall-unicode.js", "built-ins/RegExp/dotall/without-dotall.js", "built-ins/Function/prototype/toString/unicode.js", "built-ins/RegExp/property-escapes/character-class.js", ]}, { level: 1, desc: "taggedTemplateOperatorPrecedence", files: [ "language/expressions/tagged-template/constructor-invocation.js" ]}, // buble bug: Creating a static element with a computed name `prototype` should be a runtime error { level: 1, desc: "staticPrototypeElement", files: [ "language/statements/class/static-method-non-configurable-err.js" ]}, // buble bug: for-of String iteration by byte { level: 1, desc: "stringByte", files: [ "language/statements/for-of/string-astral.js", ]}, // buble bug: allows constructors to return !== undefined { level: 1, desc: "returnNotUndefined", files: [ "built-ins/Function/internals/Construct/derived-return-val.js", "language/statements/class/subclass/derived-class-return-override-with-number.js", "language/statements/class/subclass/derived-class-return-override-with-string.js", "language/statements/class/subclass/derived-class-return-override-with-boolean.js", "language/statements/class/subclass/derived-class-return-override-with-null.js", "language/statements/class/subclass/derived-class-return-override-with-symbol.js", ]}, // buble bug: allows constructors to be called without new { level: 1, desc: "noNewConstructor", files: [ "language/statements/class/subclass/default-constructor.js", "language/statements/class/subclass/default-constructor-2.js", "language/statements/class/subclass/binding.js", "language/statements/class/arguments/default-constructor.js", "built-ins/Function/internals/Call/class-ctor.js", ]}, // buble bug: instantiating a class extending null should throw { level: 1, desc: "extendsNull", files: [ "language/statements/class/subclass/class-definition-null-proto-this.js" ]}, // buble bug: lexically scoped variables have no temporal dead zone { level: 1, desc: "tdz", files: [ "*before-initialization*", "*(init|put)-let*", "*bound-names-fordecl-tdz.js" ]}, // buble bug: lexically scoped destructuring declarations in for-of heads // s2: for ({x} of []) a.push(() => x) { level: 2, desc: "lexicalDestructuringForOf", files: [ "language/statements/for-of/scope-body-lex-boundary.js", "language/statements/for/scope-body-lex-boundary.js", "language/statements/for-in/scope-body-lex-boundary.js", ]}, // buble bug: lexically scoped destructuring declarations in for-of heads // 'var a = []; for (let [x] of []) a.push(() => x)' // buble bug: scope with classes { level: 1, desc: "lexicalScopingWithLoopsAndClassesAndStuff", files: [ "language/statements/for-of/dstr/array-rest-nested-array-null.js", "language/statements/for-of/dstr/array-rest-nested-obj-null.js", "language/statements/for-of/dstr/array-rest-nested-obj-undefined-hole.js", "language/statements/for-of/dstr/array-rest-nested-obj-undefined-own.js", "language/statements/for-of/dstr/array-rest-nested-obj-undefined.js", "language/expressions/class/scope-name-lex-open-heritage.js", "language/expressions/class/scope-name-lex-open-no-heritage.js", //"language/expressions/call/scope-lex-open.js", "language/statements/switch/scope-lex-open-case.js", "language/statements/switch/scope-lex-open-dflt.js", "language/statements/for-in/scope-head-lex-open.js", "language/statements/for-in/scope-body-lex-open.js", //"language/statements/for/scope-head-lex-open.js", "language/statements/for/scope-body-lex-open.js", "language/statements/class/scope-name-lex-open-heritage.js", "language/statements/class/scope-name-lex-open-no-heritage.js", //"language/statements/block/scope-lex-open.js", "language/statements/for-of/scope-head-lex-open.js", "language/statements/for-of/scope-body-lex-open.js", "language/statements/try/scope-catch-param-lex-open.js", //"language/statements/try/scope-catch-block-lex-open.js", //"language/expressions/class/scope-name-lex-close.js", //"language/expressions/call/scope-lex-close.js", "language/statements/switch/scope-lex-close-dflt.js", "language/statements/switch/scope-lex-close-case.js", "language/statements/for-in/scope-head-lex-close.js", "language/statements/for-in/scope-body-lex-close.js", //"language/statements/for/scope-head-lex-close.js", "language/statements/class/scope-name-lex-close.js", //"language/statements/block/scope-lex-close.js", "language/statements/for-of/scope-head-lex-close.js", "language/statements/for-of/scope-body-lex-close.js", //"language/statements/try/scope-catch-block-lex-close.js", //"language/statements/try/scope-catch-param-lex-close.js", ]}, // buble bug: allows classes to extend itself { level: 1, desc: "superClassSelf", files: [ "language/statements/class/name-binding/in-extends-expression-assigned.js", "language/statements/class/name-binding/in-extends-expression.js", ]}, // buble bug: allows classes to be redefined { level: 1, desc: "classDeclarationConst", files: [ "language/statements/class/name-binding/const.js" ]}, // buble bug: Does not invalidate earlier references to lexically-scoped bindings { level: 1, desc: "invalidReferencesToLexicalBindings", files: [ "language/module-code/instn-local-bndng-cls.js", "language/module-code/instn-local-bndng-let.js" ]}, // buble bug: complicated destructuring { level: 2, desc: "complicatedDestructuring", files: [ "language/statements/for-of/dstr/array-elem-iter-thrw-close-err.js", "language/statements/for-of/dstr/array-elem-iter-thrw-close.js", "language/statements/for-of/dstr/array-elem-trlg-iter-list-thrw-close-err.js", "language/statements/for-of/dstr/array-elem-trlg-iter-list-thrw-close.js", "language/statements/for-of/dstr/array-elem-trlg-iter-rest-thrw-close-err.js", "language/statements/for-of/dstr/array-elem-trlg-iter-rest-thrw-close.js", "language/statements/for-of/dstr/array-rest-iter-thrw-close-err.js", "language/statements/for-of/dstr/array-rest-iter-thrw-close.js", "language/statements/for-of/dstr/array-rest-lref-err.js", "language/statements/for-of/dstr/array-rest-nested-array-iter-thrw-close-skip.js", ]}, // buble bug: does not close over let in for head { level: 1, desc: "letClosureForHead", files: [ "*let-closure-inside-*" ]}, // buble bug: lexical declarations should shadow globals { level: 1, desc: "lexicalShadowGlobals", files: [ "language/global-code/decl-lex-configurable-global.js", ]}, // buble bug: does not support member or parenthesized expressions in for-of head { level: 3, desc: "moreTypesForOfHead", files: [ "language/statements/for-of/head-lhs-cover.js", "language/statements/for-of/head-lhs-member.js", "language/statements/for-of/body-put-error.js", ]}, { level: 1, desc: "forOfNonArray", files: [ "*for-of/(map|set)*" ]}, // 'for (let[x] of a){x()}' { level: 1, desc: "destructuringLetForOfHeadNoSpace", files: [ "language/statements/for-of/head-let-destructuring.js" ]}, { level: 2, desc: "destructuringArrayElidedElements", files: [ "*assignment/dstr/array-elision-*" ]}, { level: 1, desc: "destructuringArrayElidedElements", files: [ "*dstr/array-(elision|empty)-(iter|val-(bool|null|num|symbol|undef))*" ]}, { level: 1, desc: "destructuringNullUndefined", files: [ "language/expressions/assignment/dstr/obj-rest-val-null.js", "language/expressions/assignment/dstr/obj-rest-val-undefined.js", ]}, { level: 2, desc: "destructuringEmptyVal", files: [ "*assignment/dstr/(array|obj)-empty*" ]}, { level: 4, desc: "generators", files: [ "*Generator*", "*generator*", "*gen-meth-*", "*gen-func-*", "*gen-named-func-expr-*", "*gen-method*", "*async-gen-*", "*fn-name-gen.js", "*for-await-resolution-and-error-agen*", "*async-func-dstr-const-async-*", "*async-func-dstr-let-async-*", "*async-func-dstr-var-async-*", "*AsyncIteratorPrototype*", "*AsyncFromSyncIteratorPrototype*", "built-ins/Object/prototype/toString/proxy-function.js", 'language/expressions/dynamic-import/assignment-expression/yield-(assign-expr|expr|star).js', "built-ins/TypedArrayConstructors/ctors/object-arg/iterating-throws.js", "harness/isConstructor.js", "language/expressions/await/for-await-of-interleaved.js", "language/module-code/instn-iee-bndng-gen.js", "language/module-code/instn-uniq-env-rec.js", "annexB/built-ins/RegExp/RegExp-control-escape-russian-letter.js", "annexB/built-ins/RegExp/RegExp-invalid-control-escape-character-class.js", "language/expressions/array/spread-err-mult-err-expr-throws.js", "language/expressions/array/spread-err-sngl-err-expr-throws.js", "*(ary-elision-init|ary-elision-iter|ary-empty-init|elision-exhausted|elision-step-err|ptrn-elision|dstr/(meth-|const-|let-|var-)?(static-)?(dflt-)?ary-ptrn(-rest-ary)?-empty|rest-ary-elision|rest-ary-empty|rest-id-elision-next-err|rest-id-iter-step-err).js", "*for*(elision|id)-iter-close.js", "language/statements/for/dstr/let-ary-init-iter-close.js", "language/statements/for/dstr/const-ary-init-iter-close.js", "language/statements/for-await-of/async-func-dstr-const-async-ary-init-iter-close.js", "language/statements/for-await-of/async-func-dstr-var-async-ary-init-iter-close.js", "language/statements/for-await-of/async-func-dstr-let-async-ary-init-iter-close.js", "language/expressions/assignment/dstr/array-elem-init-yield-expr.js", "language/expressions/assignment/dstr/array-elem-iter-rtrn-close-err.js", "language/expressions/assignment/dstr/array-elem-iter-rtrn-close-null.js", "language/expressions/assignment/dstr/array-elem-iter-rtrn-close.js", "language/expressions/assignment/dstr/array-elem-nested-array-yield-expr.js", "language/expressions/assignment/dstr/array-elem-nested-obj-yield-expr.js", "language/expressions/assignment/dstr/array-elem-target-yield-expr.js", "language/expressions/assignment/dstr/array-elem-trlg-iter-list-rtrn-close-null.js", "language/expressions/assignment/dstr/array-elem-trlg-iter-list-rtrn-close-err.js", "language/expressions/assignment/dstr/array-elem-trlg-iter-list-rtrn-close.js", "language/expressions/assignment/dstr/array-elem-trlg-iter-rest-rtrn-close-err.js", "language/expressions/assignment/dstr/array-elem-trlg-iter-rest-rtrn-close-null.js", "language/expressions/assignment/dstr/array-elem-trlg-iter-rest-rtrn-close.js", "language/expressions/assignment/dstr/array-iteration.js", "language/expressions/assignment/dstr/array-rest-iter-rtrn-close-err.js", "language/expressions/assignment/dstr/array-rest-iter-rtrn-close-null.js", "language/expressions/assignment/dstr/array-rest-iter-rtrn-close.js", "language/expressions/assignment/dstr/array-rest-iteration.js", "language/expressions/assignment/dstr/array-rest-nested-array-yield-expr.js", "language/expressions/assignment/dstr/array-rest-nested-obj-yield-expr.js", "language/expressions/assignment/dstr/array-rest-yield-expr.js", "language/expressions/assignment/dstr/obj-id-init-yield-expr.js", "language/expressions/assignment/dstr/obj-prop-elem-init-yield-expr.js", "language/expressions/assignment/dstr/obj-prop-elem-target-yield-expr.js", "language/expressions/assignment/dstr/obj-prop-nested-array-yield-expr.js", "language/expressions/assignment/dstr/obj-prop-nested-obj-yield-expr.js", "language/expressions/call/spread-err-mult-err-expr-throws.js", "language/expressions/call/spread-err-sngl-err-expr-throws.js", "language/expressions/new/spread-err-mult-err-expr-throws.js", "language/expressions/new/spread-err-sngl-err-expr-throws.js", "language/expressions/object/accessor-name-computed-yield-expr.js", "language/expressions/super/call-spread-err-mult-err-expr-throws.js", "language/expressions/super/call-spread-err-sngl-err-expr-throws.js", "language/expressions/yield/arguments-object-attributes.js", "language/expressions/yield/captured-free-vars.js", "language/expressions/yield/formal-parameters-after-reassignment-strict.js", "language/expressions/yield/formal-parameters.js", "language/expressions/yield/from-catch.js", "language/expressions/yield/from-try.js", "language/expressions/yield/in-rltn-expr.js", "language/expressions/yield/iter-value-specified.js", "language/expressions/yield/iter-value-unspecified.js", "language/expressions/yield/rhs-iter.js", "language/expressions/yield/rhs-omitted.js", "language/expressions/yield/rhs-primitive.js", "language/expressions/yield/rhs-regexp.js", "language/expressions/yield/rhs-template-middle.js", "language/expressions/yield/rhs-unresolvable.js", "language/expressions/yield/rhs-yield.js", "language/expressions/yield/star-array.js", "language/expressions/yield/star-in-rltn-expr.js", "language/expressions/yield/star-iterable.js", "language/expressions/yield/star-rhs-iter-get-call-err.js", "language/expressions/yield/star-rhs-iter-get-call-non-obj.js", "language/expressions/yield/star-rhs-iter-get-get-err.js", "language/expressions/yield/star-rhs-iter-nrml-next-call-err.js", "language/expressions/yield/star-rhs-iter-nrml-next-call-non-obj.js", "language/expressions/yield/star-rhs-iter-nrml-next-get-err.js", "language/expressions/yield/star-rhs-iter-nrml-next-invoke.js", "language/expressions/yield/star-rhs-iter-nrml-res-done-err.js", "language/expressions/yield/star-rhs-iter-nrml-res-done-no-value.js", "language/expressions/yield/star-rhs-iter-nrml-res-value-err.js", "language/expressions/yield/star-rhs-iter-nrml-res-value-final.js", "language/expressions/yield/star-rhs-iter-rtrn-no-rtrn.js", "language/expressions/yield/star-rhs-iter-rtrn-res-done-err.js", "language/expressions/yield/star-rhs-iter-rtrn-res-done-no-value.js", "language/expressions/yield/star-rhs-iter-rtrn-res-value-err.js", "language/expressions/yield/star-rhs-iter-rtrn-res-value-final.js", "language/expressions/yield/star-rhs-iter-rtrn-rtrn-call-err.js", "language/expressions/yield/star-rhs-iter-rtrn-rtrn-call-non-obj.js", "language/expressions/yield/star-rhs-iter-rtrn-rtrn-get-err.js", "language/expressions/yield/star-rhs-iter-rtrn-rtrn-invoke.js", "language/expressions/yield/star-rhs-iter-thrw-res-done-err.js", "language/expressions/yield/star-rhs-iter-thrw-res-done-no-value.js", "language/expressions/yield/star-rhs-iter-thrw-res-value-err.js", "language/expressions/yield/star-rhs-iter-thrw-res-value-final.js", "language/expressions/yield/star-rhs-iter-thrw-thrw-call-err.js", "language/expressions/yield/star-rhs-iter-thrw-thrw-call-non-obj.js", "language/expressions/yield/star-rhs-iter-thrw-thrw-get-err.js", "language/expressions/yield/star-rhs-iter-thrw-thrw-invoke.js", "language/expressions/yield/star-rhs-iter-thrw-violation-no-rtrn.js", "language/expressions/yield/star-rhs-iter-thrw-violation-rtrn-call-err.js", "language/expressions/yield/star-rhs-iter-thrw-violation-rtrn-call-non-obj.js", "language/expressions/yield/star-rhs-iter-thrw-violation-rtrn-get-err.js", "language/expressions/yield/star-rhs-iter-thrw-violation-rtrn-invoke.js", "language/expressions/yield/star-rhs-unresolvable.js", "language/expressions/yield/star-string.js", "language/expressions/yield/then-return.js", "language/expressions/yield/within-for.js", "language/statements/class/static-method-gen-non-configurable-err.js", "language/statements/for-await-of/async-func-decl-dstr-array-rest-iteration.js", "language/statements/for-of/break-from-catch.js", "language/statements/for-of/break-from-finally.js", "language/statements/for-of/break-from-try.js", "language/statements/for-of/break-label-from-catch.js", "language/statements/for-of/break-label-from-finally.js", "language/statements/for-of/break-label-from-try.js", "language/statements/for-of/break-label.js", "language/statements/for-of/break.js", "language/statements/for-of/continue-from-catch.js", "language/statements/for-of/continue-from-finally.js", "language/statements/for-of/continue-from-try.js", "language/statements/for-of/continue-label-from-catch.js", "language/statements/for-of/continue-label-from-finally.js", "language/statements/for-of/continue-label-from-try.js", "language/statements/for-of/continue-label.js", "language/statements/for-of/continue.js", "language/statements/for-of/dstr/array-elem-init-yield-expr.js", "language/statements/for-of/dstr/array-elem-iter-rtrn-close-err.js", "language/statements/for-of/dstr/array-elem-iter-rtrn-close-null.js", "language/statements/for-of/dstr/array-elem-iter-rtrn-close.js", "language/statements/for-of/dstr/array-elem-nested-array-yield-expr.js", "language/statements/for-of/dstr/array-elem-nested-obj-yield-expr.js", "language/statements/for-of/dstr/array-elem-target-yield-expr.js", "language/statements/for-of/dstr/array-elem-trlg-iter-list-rtrn-close-err.js", "language/statements/for-of/dstr/array-elem-trlg-iter-list-rtrn-close-null.js", "language/statements/for-of/dstr/array-elem-trlg-iter-list-rtrn-close.js", "language/statements/for-of/dstr/array-elem-trlg-iter-rest-rtrn-close-err.js", "language/statements/for-of/dstr/array-elem-trlg-iter-rest-rtrn-close-null.js", "language/statements/for-of/dstr/array-elem-trlg-iter-rest-rtrn-close.js", "language/statements/for-of/dstr/array-iteration.js", "language/statements/for-of/dstr/array-rest-iter-rtrn-close-err.js", "language/statements/for-of/dstr/array-rest-iter-rtrn-close-null.js", "language/statements/for-of/dstr/array-rest-iter-rtrn-close.js", "language/statements/for-of/dstr/array-rest-iteration.js", "language/statements/for-of/dstr/array-rest-nested-array-yield-expr.js", "language/statements/for-of/dstr/array-rest-nested-obj-yield-expr.js", "language/statements/for-of/dstr/array-rest-yield-expr.js", "language/statements/for-of/dstr/obj-id-init-yield-expr.js", "language/statements/for-of/dstr/obj-prop-elem-init-yield-expr.js", "language/statements/for-of/dstr/obj-prop-elem-target-yield-expr.js", "language/statements/for-of/dstr/obj-prop-nested-array-yield-expr.js", "language/statements/for-of/dstr/obj-prop-nested-obj-yield-expr.js", "language/statements/for-of/nested.js", "language/statements/for-of/return-from-catch.js", "language/statements/for-of/return-from-finally.js", "language/statements/for-of/return-from-try.js", "language/statements/for-of/return.js", "language/statements/for-of/throw-from-catch.js", "language/statements/for-of/throw-from-finally.js", "language/statements/for-of/throw.js", "language/statements/for-of/yield-from-catch.js", "language/statements/for-of/yield-from-finally.js", "language/statements/for-of/yield-from-try.js", "language/statements/for-of/yield-star-from-catch.js", "language/statements/for-of/yield-star-from-finally.js", "language/statements/for-of/yield-star-from-try.js", "language/statements/for-of/yield-star.js", "language/statements/for-of/yield.js", "annexB/language/expressions/yield/star-iterable-return-emulates-undefined-throws-when-called.js", "language/expressions/object/method-definition/gen-yield-spread-arr-multiple.js", "language/expressions/object/method-definition/gen-yield-spread-arr-single.js", "language/expressions/object/method-definition/gen-yield-spread-obj.js", "language/expressions/object/method-definition/yield-as-expression-with-rhs.js", "language/expressions/object/method-definition/yield-as-expression-without-rhs.js", "language/expressions/object/method-definition/yield-as-literal-property-name.js", "language/expressions/object/method-definition/yield-as-property-name.js", "language/expressions/object/method-definition/yield-as-statement.js", "language/expressions/object/method-definition/yield-as-yield-operand.js", "language/expressions/object/method-definition/yield-newline.js", "language/expressions/object/method-definition/yield-return.js", "language/expressions/object/method-definition/yield-star-before-newline.js", "language/statements/class/definition/fn-name-static-precedence.js", "language/statements/class/definition/methods-gen-*", ]}, { level: 3, desc: "unicodeFeatures", files: [ 'built-ins/RegExp/property-escapes/generated/Extended_Pictographic.js', 'built-ins/RegExp/property-escapes/generated/Script_-_Dogra.js', 'built-ins/RegExp/property-escapes/generated/Script_-_Gunjala_Gondi.js', 'built-ins/RegExp/property-escapes/generated/Script_-_Hanifi_Rohingya.js', 'built-ins/RegExp/property-escapes/generated/Script_-_Makasar.js', 'built-ins/RegExp/property-escapes/generated/Script_-_Medefaidrin.js', 'built-ins/RegExp/property-escapes/generated/Script_-_Old_Sogdian.js', 'built-ins/RegExp/property-escapes/generated/Script_-_Sogdian.js', 'built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Dogra.js', 'built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Gunjala_Gondi.js', 'built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Hanifi_Rohingya.js', 'built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Makasar.js', 'built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Medefaidrin.js', 'built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Old_Sogdian.js', 'built-ins/RegExp/property-escapes/generated/Script_Extensions_-_Sogdian.js', ]}, { level: 3, desc: "unsupportedFeatureExportNsAsFrom", files: [ "language/module-code/instn-once.js", ]}, // buble bug: cannot transpile static method called name { level: 1, desc: "staticName", files: [ "*/(dstr/(array-elem|(|const-|dflt-|let-|meth-|meth-dflt-|meth-static-|meth-static-dflt-)(ary-ptrn-elem|obj-ptrn)-id|obj-id|obj-prop-elem|var-ary-ptrn-elem-id|var-obj-ptrn-id)-init-)?fn-name-class.js", ]}, { level: 1, desc: "spreadForOfIterators", files: [ "annexB/language/statements/for-of/iterator-close-return-emulates-undefined-throws-when-called.js", "language/expressions/assignment/dstr/array-rest-lref-err.js", "language/statements/for-of/head-expr-to-obj.js", "language/statements/for-of/head-expr-primitive-iterator-method.js", "language/statements/for-of/head-expr-obj-iterator-method.js", "language/statements/for-of/dstr/obj-empty-undef.js", "language/statements/for-of/dstr/obj-empty-null.js", "built-ins/ArrayIteratorPrototype/next/detach-typedarray-in-progress.js", "language/statements/for-of/Array.prototype.(entries|keys|Symbol.iterator).js", "language/statements/for-of/body-dstr-assign-error.js", "*call-spread-err-(mult|sngl)-err-i*", "*call-spread-(mult|sngl)-iter*", "language/statements/class/constructor-inferred-observable-iteration.js", "*dstr/(array|(const-|dflt-|let-|meth-|meth-dflt-|meth-static-|meth-static-dflt-|var-)?ary)-((elem-(|trlg-)|elision-|empty-|rest-(elision-)?|*-)iter-(val-err|step-err|close|get-err|(list-|rest-)?(nrml-|thrw-|)close(-err|-null|-skip|)|abpt)|rest-lref).js", "language/statements/for-of/generic-iterable.js", "language/statements/for-of/iterator-*", "*spread-err-(mult|sngl)-err-it*", "*spread-(mult|sngl)-it*", "language/statements/class/subclass/default-constructor-spread-override.js", ]}, // buble bug: emits code with invalid runtime behavior for rest properties in for-of loop heads // https://github.com/bublejs/buble/issues/110 { level: 1, desc: "invalidRestPropertiesForOf", files: [ "*/for-of/dstr/obj-rest-(c|d|e|n|o|p|s|t|v)*", "*/for-of/dstr/obj-rest-getter.js", ]}, // buble bug: subclassing of builtins does not work { level: 1, desc: "subclassingBuiltins", files: [ "built-ins/ArrayBuffer/isView/arg-is-(dataview|typedarray)-subclass-instance.js", "built-ins/Promise/(all|race|reject|resolve)/ctx-ctor.js", "built-ins/Promise/prototype/then/capability-executor-called-twice.js", "built-ins/Promise/prototype/then/capability-executor-not-callable.js", "built-ins/Promise/prototype/then/ctor-custom.js", "built-ins/Promise/prototype/then/deferred-is-resolved-value.js", "language/statements/class/subclass/builtins.js", "language/statements/class/subclass/builtin-objects/Array/contructor-calls-super-multiple-arguments.js", "language/statements/class/subclass/builtin-objects/Array/contructor-calls-super-single-argument.js", "language/statements/class/subclass/builtin-objects/Array/length.js", "language/statements/class/subclass/builtin-objects/(Array(Buffer)?|Boolean|DataView|Date|Error|Function|Map|Number|Promise|RegExp|Set|String|TypedArray|WeakMap|WeakSet)/(regular-subclassing|super-must-be-called).js", "language/statements/class/subclass/builtin-objects/Error/message-property-assignment.js", "language/statements/class/subclass/builtin-objects/Function/instance-length.js", "language/statements/class/subclass/builtin-objects/Function/instance-name.js", "language/statements/class/subclass/builtin-objects/NativeError/*Error-(message|super).js", "language/statements/class/subclass/builtin-objects/Object/constructor-return-undefined-throws.js", "language/statements/class/subclass/builtin-objects/Object/constructor-returns-non-object.js", "language/statements/class/subclass/builtin-objects/RegExp/lastIndex.js", "language/statements/class/subclass/builtin-objects/String/length.js", "language/statements/class/subclass/builtin-objects/Symbol/new-symbol-with-super-throws.js", "built-ins/Promise/prototype/finally/species-constructor.js", "built-ins/Promise/prototype/finally/subclass-reject-count.js", "built-ins/Promise/prototype/finally/subclass-resolve-count.js", ]}, { level: 4, desc: "modules", files: [ "language/expressions/dynamic-import/imported-self-update.js", "language/expressions/dynamic-import/reuse-namespace-object-from-import.js", "*/eval-export-*", "*/eval-gtbndng-indirect-*", "*/instn-iee-bndng-(cls|const|fun|let|var).js", "*/instn-iee-err-*", "*/instn-local-bndng-export-*", "*/instn-named-*", "*/instn-resolve-*", "*/instn-star-*", "language/module-code/namespace/*", "language/module-code/eval-rqstd-*", "language/module-code/eval-self-once.js", "language/module-code/instn-local-bndng-gen.js", "language/module-code/instn-iee-iee-cycle.js", "language/module-code/instn-iee-star-cycle.js", "language/module-code/instn-iee-trlng-comma.js", "language/module-code/instn-same-global.js", "language/module-code/parse-export-empty.js", ]}, { level: 4, desc: "sticky", files: [ "*/y-*", "*-y-*", "built-ins/RegExp/prototype/(flags/coercion-sticky.js|sticky/*)", "built-ins/RegExp/prototype/Symbol.match/builtin-coerce-lastindex.js", "built-ins/RegExp/prototype/Symbol.split/coerce-flags.js", "built-ins/RegExp/prototype/Symbol.split/species-ctor-y.js", "built-ins/RegExp/prototype/Symbol.split/species-ctor.js", 'built-ins/RegExp/prototype/dotAll/this-val-regexp.js', 'built-ins/RegExp/prototype/flags/this-val-regexp.js', ]}, // Contrary to what I argued in https://github.com/bublejs/buble/pull/67 // and what V8 does, the template cache is keyed based on node, not content. { level: 1, desc: "taggedTemplateRegistry", files: [ "language/expressions/tagged-template/cache-(differing-expressions|identical-source).js", "language/expressions/tagged-template/template-object-template-map.js", ]}, ].map(i => ({ config: i.config, desc: i.desc, level: i.level, pattern: mapFilePatterns(i.files) })); exports.skip_list = [ // FIXME: Do we skip these (instead of expect fail) because they work in some nodejs versions? { desc: "matchAll", files: [ "built-ins/RegExpStringIteratorPrototype/*", "built-ins/RegExp/prototype/Symbol.matchAll/*", "built-ins/String/prototype/matchAll/*" ] }, { desc: "dotall", files: [ "annexB/built-ins/RegExp/prototype/flags/order-after-compile.js", "built-ins/RegExp/prototype/flags/rethrow.js", "built-ins/RegExp/prototype/flags/get-order.js", ]}, // Runtime behaviour { desc: 'runtimeRegexp', files: [ 'built-ins/RegExp/duplicate-flags.js', ] }, { desc: "tco", files: [ "language/(expressions/tagged-template|statements/for)/tco-*" ] }, { desc: "runtimeBigInt", files: [ "built-ins/BigInt/asIntN/bigint-tobigint-errors.js", "built-ins/BigInt/asUintN/bigint-tobigint-errors.js", "built-ins/DataView/prototype/(g|s)etBig(Ui|I)nt64/*", "built-ins/JSON/stringify/bigint-cross-realm.js", "built-ins/Object/prototype/toString/symbol-*-bigint.js", "built-ins/TypedArrayConstructors/ctors-bigint/*", "built-ins/TypedArrayConstructors/from/BigInt/*", ] }, { desc: "runtimeRegexpNamedGroups", files: [ "built-ins/RegExp/named-groups/(f|groups-object-(undefined|subclass(-sans)?)|string-replace-(e|g|m|n|u)|unicode-match)*", ]}, { desc: "trim", files: [ "built-ins/String/prototype/trim(End|Start)/*" ] }, { desc: "Symbol.prototype.description", files: [ "built-ins/Symbol/prototype/description/*" ] }, // Not available in Node 4 { desc: "Symbol.match", files: [ "built-ins/RegExp/prototype/Symbol.match/*" ] }, { desc: "Symbol.replace", files: [ "built-ins/RegExp/prototype/Symbol.replace/*" ] }, { desc: "Symbol.search", files: [ "built-ins/RegExp/prototype/Symbol.search/*" ] }, { desc: "Symbol.split", files: [ "built-ins/RegExp/prototype/Symbol.split/*" ] }, // Don't know how to detach an ArrayBuffer in node 4 { desc: "detach", files: [ "built-ins/TypedArray/prototype/sort/sort-tonumber.js", "built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-to-number-detachbuffer.js", "built-ins/TypedArrayConstructors/ctors/buffer-arg/detachedbuffer.js", "built-ins/TypedArrayConstructors/ctors/buffer-arg/length-to-number-detachbuffer.js", ] }, // Non-syntax { desc: "intl402", files: [ "intl402/*" ] }, { desc: "Atomics", files: [ "built-ins/Atomics/*" ] }, { desc: "Object.fromEntries", files: [ "built-ins/Object/fromEntries/*" ] }, { desc: "Object.keys", files: [ "built-ins/Object/keys/property-traps-order-with-proxied-array.js" ] }, { desc: "Array.prototype.flat(Map)", files: [ "built-ins/Array/prototype/flat*" ] }, { desc: "SharedArrayBuffer", files: [ "built-ins/DataView/custom-proto-access-throws-sab.js", "built-ins/TypedArrayConstructors/ctors/buffer-arg/custom-proto-access-throws-sab.js", "built-ins/TypedArrayConstructors/ctors/buffer-arg/length-access-throws-sab.js", ]}, { desc: "Object.values", files: [ "built-ins/JSON/stringify/string-escape-ascii.js", "built-ins/Object/values/*" ]}, { desc: "Object.entries", files: [ "built-ins/Object/entries/*" ]}, { desc: "Proxy", files: [ "built-ins/Object/keys/proxy-keys.js", "built-ins/Proxy/enumerate/removed-does-not-trigger.js", "built-ins/Proxy/get/trap-is-undefined-receiver.js", "built-ins/Proxy/set/trap-is-undefined-receiver.js", "built-ins/Array/prototype/slice/length-exceeding-integer-limit-proxied-array.js:", ]}, { desc: "Symbol.species", files: [ "built-ins/Symbol/species/subclassing.js", "built-ins/TypedArrayConstructors/ctors/typedarray-arg/same-ctor-buffer-ctor-species-not-ctor.js", "built-ins/TypedArrayConstructors/ctors/typedarray-arg/same-ctor-buffer-ctor-species-prototype-throws.js", "built-ins/TypedArrayConstructors/ctors/typedarray-arg/same-ctor-buffer-ctor-species-throws.js", ] }, { desc: "Reflect", files: [ "built-ins/DataView/custom-proto-access-detaches-buffer.js", "built-ins/DataView/custom-proto-access-throws.js", "language/expressions/super/realm.js", "built-ins/TypedArrayConstructors/ctors/*/custom-proto-access-throws.js", "built-ins/RegExp/CharacterClassEscapes/character-class-digit-class-escape-flags-u.js", "built-ins/RegExp/CharacterClassEscapes/character-class-digit-class-escape-plus-quantifier-flags-u.js", "built-ins/RegExp/CharacterClassEscapes/character-class-digit-class-escape-plus-quantifier.js", "built-ins/RegExp/CharacterClassEscapes/character-class-digit-class-escape.js", "built-ins/RegExp/CharacterClassEscapes/character-class-non-digit-class-escape-flags-u.js", "built-ins/RegExp/CharacterClassEscapes/character-class-non-digit-class-escape-plus-quantifier-flags-u.js", "built-ins/RegExp/CharacterClassEscapes/character-class-non-digit-class-escape-plus-quantifier.js", "built-ins/RegExp/CharacterClassEscapes/character-class-non-digit-class-escape.js", "built-ins/RegExp/CharacterClassEscapes/character-class-non-whitespace-class-escape-flags-u.js", "built-ins/RegExp/CharacterClassEscapes/character-class-non-whitespace-class-escape-plus-quantifier-flags-u.js", "built-ins/RegExp/CharacterClassEscapes/character-class-non-whitespace-class-escape-plus-quantifier.js", "built-ins/RegExp/CharacterClassEscapes/character-class-non-whitespace-class-escape.js", "built-ins/RegExp/CharacterClassEscapes/character-class-non-word-class-escape-flags-u.js", "built-ins/RegExp/CharacterClassEscapes/character-class-non-word-class-escape-plus-quantifier-flags-u.js", "built-ins/RegExp/CharacterClassEscapes/character-class-non-word-class-escape-plus-quantifier.js", "built-ins/RegExp/CharacterClassEscapes/character-class-non-word-class-escape.js", "built-ins/RegExp/CharacterClassEscapes/character-class-whitespace-class-escape-flags-u.js", "built-ins/RegExp/CharacterClassEscapes/character-class-whitespace-class-escape-plus-quantifier-flags-u.js", "built-ins/RegExp/CharacterClassEscapes/character-class-whitespace-class-escape-plus-quantifier.js", "built-ins/RegExp/CharacterClassEscapes/character-class-whitespace-class-escape.js", "built-ins/RegExp/CharacterClassEscapes/character-class-word-class-escape-flags-u.js", "built-ins/RegExp/CharacterClassEscapes/character-class-word-class-escape-plus-quantifier-flags-u.js", "built-ins/RegExp/CharacterClassEscapes/character-class-word-class-escape-plus-quantifier.js", "built-ins/RegExp/CharacterClassEscapes/character-class-word-class-escape.js", "built-ins/RegExp/property-escapes/generated/*", ] }, { desc: "Symbol.toPrimitive", files: [ "language/expressions/equals/to-prim-hint.js", "built-ins/Date/prototype/Symbol.toPrimitive/*", "built-ins/String/prototype/indexOf/position-tointeger-errors.js", "built-ins/String/prototype/indexOf/position-tointeger-toprimitive.js", "built-ins/String/prototype/indexOf/position-tointeger-wrapped-values.js", "built-ins/String/prototype/indexOf/searchstring-tostring-errors.js", "built-ins/String/prototype/indexOf/searchstring-tostring-toprimitive.js", "built-ins/String/prototype/indexOf/searchstring-tostring-wrapped-values.js", ] }, { desc: "Symbol.hasInstance", files: [ "built-ins/Function/prototype/Symbol.hasInstance/this-val-poisoned-prototype.js" ] }, { desc: "Array.prototype.includes", files: [ "built-ins/Function/prototype/toString/built-in-function-object.js" ] }, { desc: "regexpucoreIssue?", files: [ // This produces an S1 on Node < 8, but passes on Node >= 8 "built-ins/RegExp/property-escapes/generated/Assigned.js", ] }, { desc: "nodeBug_asyncEscapedLineTerminator", files: [ "language/expressions/async-arrow-function/escaped-async-line-terminator.js" ] }, { desc: "nodeBug_keyOrder", files: [ "built-ins/Reflect/ownKeys/return-on-corresponding-order-large-index.js" ] }, { desc: "nodeBug", files: [ "built-ins/Array/prototype/reverse/length-exceeding-integer-limit-with-proxy.js", "built-ins/Array/prototype/sort/comparefn-nonfunction-call-throws.js", "built-ins/Array/prototype/splice/create-species-length-exceeding-integer-limit.js", "built-ins/Array/prototype/splice/property-traps-order-with-species.js", "built-ins/Array/prototype/splice/throws-if-integer-limit-exceeded.js", "built-ins/Array/prototype/unshift/throws-if-integer-limit-exceeded.js", "built-ins/Function/prototype/toString/function-expression.js", "built-ins/Function/prototype/toString/proxy-bound-function.js", "built-ins/Function/prototype/toString/proxy-function-expression.js", "built-ins/Function/prototype/toString/proxy-arrow-function.js", "built-ins/Function/prototype/toString/proxy-class.js", "built-ins/Function/prototype/toString/proxy-method-definition.js", "built-ins/Promise/prototype/finally/this-value-non-promise.js", "language/expressions/assignment/destructuring/iterator-destructuring-property-reference-target-evaluation-order.js", "language/expressions/assignment/destructuring/keyed-destructuring-property-reference-target-evaluation-order.js", "language/statements/class/subclass/builtin-objects/Proxy/no-prototype-throws.js", "built-ins/TypedArray/prototype/fill/fill-values-conversion-once.js", "built-ins/TypedArrayConstructors/from/set-value-abrupt-completion.js", "built-ins/RegExp/prototype/Symbol.split/str-result-get-length-err.js", "built-ins/Date/prototype/toDateString/format.js", "built-ins/Date/prototype/toString/format.js", "built-ins/Date/prototype/toUTCString/format.js", "built-ins/Function/prototype/toString/well-known-intrinsic-object-functions.js", "built-ins/Number/prototype/toExponential/range.js", "built-ins/Number/prototype/toFixed/range.js", "built-ins/Number/prototype/toPrecision/range.js", "built-ins/RegExp/prototype/Symbol.match/g-match-empty-set-lastindex-err.js", "built-ins/RegExp/prototype/Symbol.search/lastindex-no-restore.js", "built-ins/RegExp/prototype/Symbol.search/set-lastindex-init-err.js", "built-ins/RegExp/prototype/Symbol.search/set-lastindex-restore-err.js", "built-ins/RegExp/prototype/Symbol.split/str-coerce-lastindex.js", "language/expressions/arrow-function/strict.js", "language/expressions/async-arrow-function/try-return-finally-throw.js", "language/expressions/async-arrow-function/try-throw-finally-throw.js", "built-ins/Date/prototype/toString/non-date-receiver.js", "built-ins/Promise/prototype/then/context-check-on-entry.js", "built-ins/TypedArrayConstructors/ctors/typedarray-arg/other-ctor-buffer-ctor-access-throws.js", ] }, { desc: "node4Bug_arrayLength", files: [ "built-ins/Array/prototype/*integer-limit*" ] }, { desc: "node4Bug_anonFunctionName", files: [ "*fn-name-(arrow|cover|fn).js" ] }, // Node < 11 { desc: "nodeBug_unstableSort", files: [ "built-ins/Array/prototype/sort/stability-(11|513|2048)*" ] }, ].map(i => ({ desc: i.desc, pattern: mapFilePatterns(i.files) })); buble-0.19.8/src/000077500000000000000000000000001350705536200134775ustar00rootroot00000000000000buble-0.19.8/src/index.js000066400000000000000000000052341350705536200151500ustar00rootroot00000000000000import { Parser } from 'acorn'; import acornJsx from 'acorn-jsx'; import acornDynamicImport from 'acorn-dynamic-import'; import Program from './program/Program.js'; import { features, matrix } from './support.js'; import getSnippet from './utils/getSnippet.js'; const parser = Parser.extend(acornDynamicImport, acornJsx()); const dangerousTransforms = ['dangerousTaggedTemplateString', 'dangerousForOf']; export function target(target) { const targets = Object.keys(target); let bitmask = targets.length ? 0b11111111111111111111111 : 0b00010000000000000000001; Object.keys(target).forEach(environment => { const versions = matrix[environment]; if (!versions) throw new Error( `Unknown environment '${environment}'. Please raise an issue at https://github.com/bublejs/buble/issues` ); const targetVersion = target[environment]; if (!(targetVersion in versions)) throw new Error( `Support data exists for the following versions of ${environment}: ${Object.keys( versions ).join( ', ' )}. Please raise an issue at https://github.com/bublejs/buble/issues` ); const support = versions[targetVersion]; bitmask &= support; }); const transforms = Object.create(null); features.forEach((name, i) => { transforms[name] = !(bitmask & (1 << i)); }); dangerousTransforms.forEach(name => { transforms[name] = false; }); return transforms; } export function transform(source, options = {}) { let ast; let jsx = null; try { ast = parser.parse(source, { ecmaVersion: 10, preserveParens: true, sourceType: 'module', allowAwaitOutsideFunction: true, allowReturnOutsideFunction: true, allowHashBang: true, onComment: (block, text) => { if (!jsx) { const match = /@jsx\s+([^\s]+)/.exec(text); if (match) jsx = match[1]; } } }); options.jsx = jsx || options.jsx; } catch (err) { err.snippet = getSnippet(source, err.loc); err.toString = () => `${err.name}: ${err.message}\n${err.snippet}`; throw err; } const transforms = target(options.target || {}); Object.keys(options.transforms || {}).forEach(name => { if (name === 'modules') { if (!('moduleImport' in options.transforms)) transforms.moduleImport = options.transforms.modules; if (!('moduleExport' in options.transforms)) transforms.moduleExport = options.transforms.modules; return; } if (!(name in transforms)) throw new Error(`Unknown transform '${name}'`); transforms[name] = options.transforms[name]; }); if (options.objectAssign === true) options.objectAssign = 'Object.assign'; return new Program(source, ast, transforms, options).export(options); } export { version as VERSION } from '../package.json'; buble-0.19.8/src/program/000077500000000000000000000000001350705536200151465ustar00rootroot00000000000000buble-0.19.8/src/program/BlockStatement.js000066400000000000000000000232341350705536200204270ustar00rootroot00000000000000import Node from './Node.js'; import Scope from './Scope.js'; import destructure from '../utils/destructure.js'; function isUseStrict(node) { if (!node) return false; if (node.type !== 'ExpressionStatement') return false; if (node.expression.type !== 'Literal') return false; return node.expression.value === 'use strict'; } export default class BlockStatement extends Node { createScope() { this.parentIsFunction = /Function/.test(this.parent.type); this.isFunctionBlock = this.parentIsFunction || this.parent.type === 'Root'; this.scope = new Scope({ block: !this.isFunctionBlock, parent: this.parent.findScope(false), declare: id => this.createdDeclarations.push(id) }); if (this.parentIsFunction) { this.parent.params.forEach(node => { this.scope.addDeclaration(node, 'param'); }); } } initialise(transforms) { this.thisAlias = null; this.argumentsAlias = null; this.defaultParameters = []; this.createdDeclarations = []; // normally the scope gets created here, during initialisation, // but in some cases (e.g. `for` statements), we need to create // the scope early, as it pertains to both the init block and // the body of the statement if (!this.scope) this.createScope(); this.body.forEach(node => node.initialise(transforms)); this.scope.consolidate(); } findLexicalBoundary() { if (this.type === 'Program') return this; if (/^Function/.test(this.parent.type)) return this; return this.parent.findLexicalBoundary(); } findScope(functionScope) { if (functionScope && !this.isFunctionBlock) return this.parent.findScope(functionScope); return this.scope; } getArgumentsAlias() { if (!this.argumentsAlias) { this.argumentsAlias = this.scope.createIdentifier('arguments'); } return this.argumentsAlias; } getArgumentsArrayAlias() { if (!this.argumentsArrayAlias) { this.argumentsArrayAlias = this.scope.createIdentifier('argsArray'); } return this.argumentsArrayAlias; } getThisAlias() { if (!this.thisAlias) { this.thisAlias = this.scope.createIdentifier('this'); } return this.thisAlias; } getIndentation() { if (this.indentation === undefined) { const source = this.program.magicString.original; const useOuter = this.synthetic || !this.body.length; let c = useOuter ? this.start : this.body[0].start; while (c && source[c] !== '\n') c -= 1; this.indentation = ''; // eslint-disable-next-line no-constant-condition while (true) { c += 1; const char = source[c]; if (char !== ' ' && char !== '\t') break; this.indentation += char; } const indentString = this.program.magicString.getIndentString(); // account for dedented class constructors let parent = this.parent; while (parent) { if (parent.kind === 'constructor' && !parent.parent.parent.superClass) { this.indentation = this.indentation.replace(indentString, ''); } parent = parent.parent; } if (useOuter) this.indentation += indentString; } return this.indentation; } transpile(code, transforms) { const indentation = this.getIndentation(); const introStatementGenerators = []; if (this.argumentsAlias) { introStatementGenerators.push((start, prefix, suffix) => { const assignment = `${prefix}var ${this.argumentsAlias} = arguments${ suffix }`; code.appendLeft(start, assignment); }); } if (this.thisAlias) { introStatementGenerators.push((start, prefix, suffix) => { const assignment = `${prefix}var ${this.thisAlias} = this${suffix}`; code.appendLeft(start, assignment); }); } if (this.argumentsArrayAlias) { introStatementGenerators.push((start, prefix, suffix) => { const i = this.scope.createIdentifier('i'); const assignment = `${prefix}var ${i} = arguments.length, ${ this.argumentsArrayAlias } = Array(${i});\n${indentation}while ( ${i}-- ) ${ this.argumentsArrayAlias }[${i}] = arguments[${i}]${suffix}`; code.appendLeft(start, assignment); }); } if (/Function/.test(this.parent.type)) { this.transpileParameters( this.parent.params, code, transforms, indentation, introStatementGenerators ); } else if ('CatchClause' === this.parent.type) { this.transpileParameters( [this.parent.param], code, transforms, indentation, introStatementGenerators ); } if (transforms.letConst && this.isFunctionBlock) { this.transpileBlockScopedIdentifiers(code); } super.transpile(code, transforms); if (this.createdDeclarations.length) { introStatementGenerators.push((start, prefix, suffix) => { const assignment = `${prefix}var ${this.createdDeclarations.join(', ')}${suffix}`; code.appendLeft(start, assignment); }); } if (this.synthetic) { if (this.parent.type === 'ArrowFunctionExpression') { const expr = this.body[0]; if (introStatementGenerators.length) { code .appendLeft(this.start, `{`) .prependRight(this.end, `${this.parent.getIndentation()}}`); code.prependRight(expr.start, `\n${indentation}return `); code.appendLeft(expr.end, `;\n`); } else if (transforms.arrow) { code.prependRight(expr.start, `{ return `); code.appendLeft(expr.end, `; }`); } } else if (introStatementGenerators.length) { code.prependRight(this.start, `{`).appendLeft(this.end, `}`); } } let start; if (isUseStrict(this.body[0])) { start = this.body[0].end; } else if (this.synthetic || this.parent.type === 'Root') { start = this.start; } else { start = this.start + 1; } const prefix = `\n${indentation}`; let suffix = ';'; introStatementGenerators.forEach((fn, i) => { if (i === introStatementGenerators.length - 1) suffix = `;\n`; fn(start, prefix, suffix); }); } transpileParameters(params, code, transforms, indentation, introStatementGenerators) { params.forEach(param => { if ( param.type === 'AssignmentPattern' && param.left.type === 'Identifier' ) { if (transforms.defaultParameter) { introStatementGenerators.push((start, prefix, suffix) => { const lhs = `${prefix}if ( ${param.left.name} === void 0 ) ${ param.left.name }`; code .prependRight(param.left.end, lhs) .move(param.left.end, param.right.end, start) .appendLeft(param.right.end, suffix); }); } } else if (param.type === 'RestElement') { if (transforms.spreadRest) { introStatementGenerators.push((start, prefix, suffix) => { const penultimateParam = params[params.length - 2]; if (penultimateParam) { code.remove( penultimateParam ? penultimateParam.end : param.start, param.end ); } else { let start = param.start, end = param.end; // TODO https://gitlab.com/Rich-Harris/buble/issues/8 while (/\s/.test(code.original[start - 1])) start -= 1; while (/\s/.test(code.original[end])) end += 1; code.remove(start, end); } const name = param.argument.name; const len = this.scope.createIdentifier('len'); const count = params.length - 1; if (count) { code.prependRight( start, `${prefix}var ${name} = [], ${len} = arguments.length - ${ count };\n${indentation}while ( ${len}-- > 0 ) ${name}[ ${ len } ] = arguments[ ${len} + ${count} ]${suffix}` ); } else { code.prependRight( start, `${prefix}var ${name} = [], ${len} = arguments.length;\n${ indentation }while ( ${len}-- ) ${name}[ ${len} ] = arguments[ ${len} ]${ suffix }` ); } }); } } else if (param.type !== 'Identifier') { if (transforms.parameterDestructuring) { const ref = this.scope.createIdentifier('ref'); destructure( code, id => this.scope.createIdentifier(id), ({ name }) => this.scope.resolveName(name), param, ref, false, introStatementGenerators ); code.prependRight(param.start, ref); } } }); } transpileBlockScopedIdentifiers(code) { Object.keys(this.scope.blockScopedDeclarations).forEach(name => { const declarations = this.scope.blockScopedDeclarations[name]; for (const declaration of declarations) { let cont = false; // TODO implement proper continue... if (declaration.kind === 'for.let') { // special case const forStatement = declaration.node.findNearest('ForStatement'); if (forStatement.shouldRewriteAsFunction) { const outerAlias = this.scope.createIdentifier(name); const innerAlias = forStatement.reassigned[name] ? this.scope.createIdentifier(name) : name; declaration.name = outerAlias; code.overwrite( declaration.node.start, declaration.node.end, outerAlias, { storeName: true } ); forStatement.aliases[name] = { outer: outerAlias, inner: innerAlias }; for (const identifier of declaration.instances) { const alias = forStatement.body.contains(identifier) ? innerAlias : outerAlias; if (name !== alias) { code.overwrite(identifier.start, identifier.end, alias, { storeName: true }); } } cont = true; } } if (!cont) { const alias = this.scope.createIdentifier(name); if (name !== alias) { declaration.name = alias; code.overwrite( declaration.node.start, declaration.node.end, alias, { storeName: true } ); for (const identifier of declaration.instances) { identifier.rewritten = true; code.overwrite(identifier.start, identifier.end, alias, { storeName: true }); } } } } }); } } buble-0.19.8/src/program/Node.js000066400000000000000000000041501350705536200163710ustar00rootroot00000000000000// used for debugging, without the noise created by // circular references function toJSON(node) { const obj = {}; Object.keys(node).forEach(key => { if ( key === 'parent' || key === 'program' || key === 'keys' || key === '__wrapped' ) return; if (Array.isArray(node[key])) { obj[key] = node[key].map(toJSON); } else if (node[key] && node[key].toJSON) { obj[key] = node[key].toJSON(); } else { obj[key] = node[key]; } }); return obj; } export default class Node { ancestor(level) { let node = this; while (level--) { node = node.parent; if (!node) return null; } return node; } contains(node) { while (node) { if (node === this) return true; node = node.parent; } return false; } findLexicalBoundary() { return this.parent.findLexicalBoundary(); } findNearest(type) { if (typeof type === 'string') type = new RegExp(`^${type}$`); if (type.test(this.type)) return this; return this.parent.findNearest(type); } unparenthesizedParent() { let node = this.parent; while (node && node.type === 'ParenthesizedExpression') { node = node.parent; } return node; } unparenthesize() { let node = this; while (node.type === 'ParenthesizedExpression') { node = node.expression; } return node; } findScope(functionScope) { return this.parent.findScope(functionScope); } getIndentation() { return this.parent.getIndentation(); } initialise(transforms) { for (const key of this.keys) { const value = this[key]; if (Array.isArray(value)) { value.forEach(node => node && node.initialise(transforms)); } else if (value && typeof value === 'object') { value.initialise(transforms); } } } toJSON() { return toJSON(this); } toString() { return this.program.magicString.original.slice(this.start, this.end); } transpile(code, transforms) { for (const key of this.keys) { const value = this[key]; if (Array.isArray(value)) { value.forEach(node => node && node.transpile(code, transforms)); } else if (value && typeof value === 'object') { value.transpile(code, transforms); } } } } buble-0.19.8/src/program/Program.js000066400000000000000000000036641350705536200171240ustar00rootroot00000000000000import MagicString from 'magic-string'; import BlockStatement from './BlockStatement.js'; import wrap from './wrap.js'; export default function Program(source, ast, transforms, options) { this.type = 'Root'; // options this.jsx = options.jsx || 'React.createElement'; this.jsxFragment = options.jsxFragment || 'React.Fragment'; this.options = options; this.source = source; this.magicString = new MagicString(source); this.ast = ast; this.depth = 0; wrap((this.body = ast), this); this.body.__proto__ = BlockStatement.prototype; this.templateLiteralQuasis = Object.create(null); for (let i = 0; i < this.body.body.length; ++i) { if (!this.body.body[i].directive) { this.prependAt = this.body.body[i].start; break; } } this.objectWithoutPropertiesHelper = null; this.indentExclusionElements = []; this.body.initialise(transforms); this.indentExclusions = Object.create(null); for (const node of this.indentExclusionElements) { for (let i = node.start; i < node.end; i += 1) { this.indentExclusions[i] = true; } } this.body.transpile(this.magicString, transforms); } Program.prototype = { export(options = {}) { return { code: this.magicString.toString(), map: this.magicString.generateMap({ file: options.file, source: options.source, includeContent: options.includeContent !== false }) }; }, findNearest() { return null; }, findScope() { return null; }, getObjectWithoutPropertiesHelper(code) { if (!this.objectWithoutPropertiesHelper) { this.objectWithoutPropertiesHelper = this.body.scope.createIdentifier('objectWithoutProperties'); code.prependLeft(this.prependAt, `function ${this.objectWithoutPropertiesHelper} (obj, exclude) { ` + `var target = {}; for (var k in obj) ` + `if (Object.prototype.hasOwnProperty.call(obj, k) && exclude.indexOf(k) === -1) ` + `target[k] = obj[k]; return target; }\n` ); } return this.objectWithoutPropertiesHelper; } }; buble-0.19.8/src/program/Scope.js000066400000000000000000000055141350705536200165620ustar00rootroot00000000000000import extractNames from './extractNames.js'; import reserved from '../utils/reserved.js'; export default function Scope(options) { options = options || {}; this.parent = options.parent; this.isBlockScope = !!options.block; this.createDeclarationCallback = options.declare; let scope = this; while (scope.isBlockScope) scope = scope.parent; this.functionScope = scope; this.identifiers = []; this.declarations = Object.create(null); this.references = Object.create(null); this.blockScopedDeclarations = this.isBlockScope ? null : Object.create(null); this.aliases = Object.create(null); } Scope.prototype = { addDeclaration(node, kind) { for (const identifier of extractNames(node)) { const name = identifier.name; const declaration = { name, node: identifier, kind, instances: [] }; this.declarations[name] = declaration; if (this.isBlockScope) { if (!this.functionScope.blockScopedDeclarations[name]) this.functionScope.blockScopedDeclarations[name] = []; this.functionScope.blockScopedDeclarations[name].push(declaration); } } }, addReference(identifier) { if (this.consolidated) { this.consolidateReference(identifier); } else { this.identifiers.push(identifier); } }, consolidate() { for (let i = 0; i < this.identifiers.length; i += 1) { // we might push to the array during consolidation, so don't cache length const identifier = this.identifiers[i]; this.consolidateReference(identifier); } this.consolidated = true; // TODO understand why this is necessary... seems bad }, consolidateReference(identifier) { const declaration = this.declarations[identifier.name]; if (declaration) { declaration.instances.push(identifier); } else { this.references[identifier.name] = true; if (this.parent) this.parent.addReference(identifier); } }, contains(name) { return ( this.declarations[name] || (this.parent ? this.parent.contains(name) : false) ); }, createIdentifier(base) { if (typeof base === 'number') base = base.toString(); base = base .replace(/\s/g, '') .replace(/\[([^\]]+)\]/g, '_$1') .replace(/[^a-zA-Z0-9_$]/g, '_') .replace(/_{2,}/, '_'); let name = base; let counter = 1; while ( this.declarations[name] || this.references[name] || this.aliases[name] || name in reserved ) { name = `${base}$${counter++}`; } this.aliases[name] = true; return name; }, createDeclaration(base) { const id = this.createIdentifier(base); this.createDeclarationCallback(id); return id; }, findDeclaration(name) { return ( this.declarations[name] || (this.parent && this.parent.findDeclaration(name)) ); }, // Sometimes, block scope declarations change name during transpilation resolveName(name) { const declaration = this.findDeclaration(name); return declaration ? declaration.name : name; } }; buble-0.19.8/src/program/extractNames.js000066400000000000000000000013001350705536200201340ustar00rootroot00000000000000export default function extractNames(node) { const names = []; extractors[node.type](names, node); return names; } const extractors = { Identifier(names, node) { names.push(node); }, ObjectPattern(names, node) { for (const prop of node.properties) { extractors[prop.type](names, prop); } }, Property(names, node) { extractors[node.value.type](names, node.value); }, ArrayPattern(names, node) { for (const element of node.elements) { if (element) extractors[element.type](names, element); } }, RestElement(names, node) { extractors[node.argument.type](names, node.argument); }, AssignmentPattern(names, node) { extractors[node.left.type](names, node.left); } }; buble-0.19.8/src/program/keys.js000066400000000000000000000000651350705536200164600ustar00rootroot00000000000000export default { Program: ['body'], Literal: [] }; buble-0.19.8/src/program/types/000077500000000000000000000000001350705536200163125ustar00rootroot00000000000000buble-0.19.8/src/program/types/ArrayExpression.js000066400000000000000000000035441350705536200220140ustar00rootroot00000000000000import Node from '../Node.js'; import spread, { isArguments, inlineSpreads } from '../../utils/spread.js'; export default class ArrayExpression extends Node { initialise(transforms) { if (transforms.spreadRest && this.elements.length) { const lexicalBoundary = this.findLexicalBoundary(); let i = this.elements.length; while (i--) { const element = this.elements[i]; if ( element && element.type === 'SpreadElement' && isArguments(element.argument) ) { this.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias(); } } } super.initialise(transforms); } transpile(code, transforms) { super.transpile(code, transforms); if (transforms.spreadRest) { inlineSpreads(code, this, this.elements); // erase trailing comma after last array element if not an array hole if (this.elements.length) { const lastElement = this.elements[this.elements.length - 1]; if ( lastElement && /\s*,/.test(code.original.slice(lastElement.end, this.end)) ) { code.overwrite(lastElement.end, this.end - 1, ' '); } } if (this.elements.length === 1) { const element = this.elements[0]; if (element && element.type === 'SpreadElement') { // special case – [ ...arguments ] if (isArguments(element.argument)) { code.overwrite( this.start, this.end, `[].concat( ${this.argumentsArrayAlias} )` ); // TODO if this is the only use of argsArray, don't bother concating } else { code.overwrite(this.start, element.argument.start, '[].concat( '); code.overwrite(element.end, this.end, ' )'); } } } else { const hasSpreadElements = spread( code, this.elements, this.start, this.argumentsArrayAlias ); if (hasSpreadElements) { code.overwrite(this.end - 1, this.end, ')'); } } } } } buble-0.19.8/src/program/types/ArrowFunctionExpression.js000066400000000000000000000040551350705536200235340ustar00rootroot00000000000000import Node from '../Node.js'; import CompileError from '../../utils/CompileError.js'; import removeTrailingComma from '../../utils/removeTrailingComma.js'; export default class ArrowFunctionExpression extends Node { initialise(transforms) { if (this.async && transforms.asyncAwait) { CompileError.missingTransform("async arrow functions", "asyncAwait", this); } this.body.createScope(); super.initialise(transforms); } transpile(code, transforms) { let openParensPos = this.start; for (let end = (this.body || this.params[0]).start - 1; code.original[openParensPos] !== '(' && openParensPos < end;) { ++openParensPos; } if (code.original[openParensPos] !== '(') openParensPos = -1; const naked = openParensPos === -1; if (transforms.arrow || this.needsArguments(transforms)) { // remove arrow let charIndex = this.body.start; while (code.original[charIndex] !== '=') { charIndex -= 1; } code.remove(charIndex, this.body.start); super.transpile(code, transforms); // wrap naked parameter if (naked) { code.prependRight(this.params[0].start, '('); code.appendLeft(this.params[0].end, ')'); } // standalone expression statement const standalone = this.parent && this.parent.type === 'ExpressionStatement'; let start, text = standalone ? '!' : ''; if (this.async) text += 'async '; text += 'function'; if (!standalone) text += ' '; if (naked) { start = this.params[0].start; } else { start = openParensPos; } // add function if (start > this.start) { code.overwrite(this.start, start, text); } else { code.prependRight(this.start, text); } } else { super.transpile(code, transforms); } if (transforms.trailingFunctionCommas && this.params.length && !naked) { removeTrailingComma(code, this.params[this.params.length - 1].end); } } // Returns whether any transforms that will happen use `arguments` needsArguments(transforms) { return ( transforms.spreadRest && this.params.filter(param => param.type === 'RestElement').length > 0 ); } } buble-0.19.8/src/program/types/AssignmentExpression.js000066400000000000000000000125451350705536200230470ustar00rootroot00000000000000import Node from '../Node.js'; import checkConst from '../../utils/checkConst.js'; import destructure from '../../utils/destructure.js'; export default class AssignmentExpression extends Node { initialise(transforms) { if (this.left.type === 'Identifier') { const declaration = this.findScope(false).findDeclaration(this.left.name); // special case – https://gitlab.com/Rich-Harris/buble/issues/11 const statement = declaration && declaration.node.ancestor(3); if ( statement && statement.type === 'ForStatement' && statement.body.contains(this) ) { statement.reassigned[this.left.name] = true; } } super.initialise(transforms); } transpile(code, transforms) { if (this.left.type === 'Identifier') { // Do this check after everything has been initialized to find // shadowing declarations after this expression checkConst(this.left, this.findScope(false)); } if (this.operator === '**=' && transforms.exponentiation) { this.transpileExponentiation(code, transforms); } else if (/Pattern/.test(this.left.type) && transforms.destructuring) { this.transpileDestructuring(code); } super.transpile(code, transforms); } transpileDestructuring(code) { const writeScope = this.findScope(true); const lookupScope = this.findScope(false); const assign = writeScope.createDeclaration('assign'); code.appendRight(this.left.end, `(${assign}`); code.appendLeft(this.right.end, ', '); const statementGenerators = []; destructure( code, id => writeScope.createDeclaration(id), node => { const name = lookupScope.resolveName(node.name); checkConst(node, lookupScope); return name; }, this.left, assign, true, statementGenerators ); let suffix = ', '; statementGenerators.forEach((fn, j) => { if (j === statementGenerators.length - 1) { suffix = ''; } fn(this.end, '', suffix); }); if (this.unparenthesizedParent().type === 'ExpressionStatement') { // no rvalue needed for expression statement code.prependRight(this.end, `)`); } else { // destructuring is part of an expression - need an rvalue code.appendRight(this.end, `, ${assign})`); } } transpileExponentiation(code) { const scope = this.findScope(false); // first, the easy part – `**=` -> `=` let charIndex = this.left.end; while (code.original[charIndex] !== '*') charIndex += 1; code.remove(charIndex, charIndex + 2); // how we do the next part depends on a number of factors – whether // this is a top-level statement, and whether we're updating a // simple or complex reference let base; const left = this.left.unparenthesize(); if (left.type === 'Identifier') { base = scope.resolveName(left.name); } else if (left.type === 'MemberExpression') { let object; let needsObjectVar = false; let property; let needsPropertyVar = false; const statement = this.findNearest(/(?:Statement|Declaration)$/); const i0 = statement.getIndentation(); if (left.property.type === 'Identifier') { property = left.computed ? scope.resolveName(left.property.name) : left.property.name; } else { property = scope.createDeclaration('property'); needsPropertyVar = true; } if (left.object.type === 'Identifier') { object = scope.resolveName(left.object.name); } else { object = scope.createDeclaration('object'); needsObjectVar = true; } if (left.start === statement.start) { if (needsObjectVar && needsPropertyVar) { code.prependRight(statement.start, `${object} = `); code.overwrite( left.object.end, left.property.start, `;\n${i0}${property} = ` ); code.overwrite( left.property.end, left.end, `;\n${i0}${object}[${property}]` ); } else if (needsObjectVar) { code.prependRight(statement.start, `${object} = `); code.appendLeft(left.object.end, `;\n${i0}`); code.appendLeft(left.object.end, object); } else if (needsPropertyVar) { code.prependRight(left.property.start, `${property} = `); code.appendLeft(left.property.end, `;\n${i0}`); code.move(left.property.start, left.property.end, this.start); code.appendLeft(left.object.end, `[${property}]`); code.remove(left.object.end, left.property.start); code.remove(left.property.end, left.end); } } else { if (needsObjectVar && needsPropertyVar) { code.prependRight(left.start, `( ${object} = `); code.overwrite( left.object.end, left.property.start, `, ${property} = ` ); code.overwrite( left.property.end, left.end, `, ${object}[${property}]` ); } else if (needsObjectVar) { code.prependRight(left.start, `( ${object} = `); code.appendLeft(left.object.end, `, ${object}`); } else if (needsPropertyVar) { code.prependRight(left.property.start, `( ${property} = `); code.appendLeft(left.property.end, `, `); code.move(left.property.start, left.property.end, left.start); code.overwrite(left.object.end, left.property.start, `[${property}]`); code.remove(left.property.end, left.end); } if (needsPropertyVar) { code.appendLeft(this.end, ` )`); } } base = object + (left.computed || needsPropertyVar ? `[${property}]` : `.${property}`); } code.prependRight(this.right.start, `Math.pow( ${base}, `); code.appendLeft(this.right.end, ` )`); } } buble-0.19.8/src/program/types/AwaitExpression.js000066400000000000000000000004551350705536200220010ustar00rootroot00000000000000import Node from '../Node.js'; import CompileError from '../../utils/CompileError.js'; export default class AwaitExpression extends Node { initialise(transforms) { if (transforms.asyncAwait) { CompileError.missingTransform("await", "asyncAwait", this); } super.initialise(transforms); } } buble-0.19.8/src/program/types/BinaryExpression.js000066400000000000000000000005551350705536200221610ustar00rootroot00000000000000import Node from '../Node.js'; export default class BinaryExpression extends Node { transpile(code, transforms) { if (this.operator === '**' && transforms.exponentiation) { code.prependRight(this.start, `Math.pow( `); code.overwrite(this.left.end, this.right.start, `, `); code.appendLeft(this.end, ` )`); } super.transpile(code, transforms); } } buble-0.19.8/src/program/types/BreakStatement.js000066400000000000000000000013301350705536200215560ustar00rootroot00000000000000import Node from '../Node.js'; import CompileError from '../../utils/CompileError.js'; import { loopStatement } from '../../utils/patterns.js'; export default class BreakStatement extends Node { initialise() { const loop = this.findNearest(loopStatement); const switchCase = this.findNearest('SwitchCase'); if (loop && (!switchCase || loop.depth > switchCase.depth)) { loop.canBreak = true; this.loop = loop; } } transpile(code) { if (this.loop && this.loop.shouldRewriteAsFunction) { if (this.label) throw new CompileError( 'Labels are not currently supported in a loop with locally-scoped variables', this ); code.overwrite(this.start, this.start + 5, `return 'break'`); } } } buble-0.19.8/src/program/types/CallExpression.js000066400000000000000000000065201350705536200216060ustar00rootroot00000000000000import Node from '../Node.js'; import spread, { isArguments, inlineSpreads, needsParentheses } from '../../utils/spread.js'; import removeTrailingComma from '../../utils/removeTrailingComma.js'; export default class CallExpression extends Node { initialise(transforms) { if (transforms.spreadRest && this.arguments.length > 1) { const lexicalBoundary = this.findLexicalBoundary(); let i = this.arguments.length; while (i--) { const arg = this.arguments[i]; if (arg.type === 'SpreadElement' && isArguments(arg.argument)) { this.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias(); } } } super.initialise(transforms); } transpile(code, transforms) { if (transforms.spreadRest && this.arguments.length) { inlineSpreads(code, this, this.arguments); // this.arguments.length may have changed, must retest. } if (transforms.spreadRest && this.arguments.length) { let hasSpreadElements = false; let context; const firstArgument = this.arguments[0]; if (this.arguments.length === 1) { if (firstArgument.type === 'SpreadElement') { code.remove(firstArgument.start, firstArgument.argument.start); hasSpreadElements = true; } } else { hasSpreadElements = spread( code, this.arguments, firstArgument.start, this.argumentsArrayAlias ); } if (hasSpreadElements) { // we need to handle super() and super.method() differently // due to its instance let _super = null; if (this.callee.type === 'Super') { _super = this.callee; } else if ( this.callee.type === 'MemberExpression' && this.callee.object.type === 'Super' ) { _super = this.callee.object; } if (!_super && this.callee.type === 'MemberExpression') { if (this.callee.object.type === 'Identifier') { context = this.callee.object.name; } else { context = this.findScope(true).createDeclaration('ref'); const callExpression = this.callee.object; code.prependRight(callExpression.start, `(${context} = `); code.appendLeft(callExpression.end, `)`); } } else { context = 'void 0'; } code.appendLeft(this.callee.end, '.apply'); if (_super) { _super.noCall = true; // bit hacky... if (this.arguments.length > 1) { if (firstArgument.type === 'SpreadElement') { if (needsParentheses(firstArgument.argument)) { code.prependRight(firstArgument.start, `( `); } } else { code.prependRight(firstArgument.start, `[ `); } code.appendLeft( this.arguments[this.arguments.length - 1].end, ' )' ); } } else if (this.arguments.length === 1) { code.prependRight(firstArgument.start, `${context}, `); } else { if (firstArgument.type === 'SpreadElement') { if (needsParentheses(firstArgument.argument)) { code.appendLeft(firstArgument.start, `${context}, ( `); } else { code.appendLeft(firstArgument.start, `${context}, `); } } else { code.appendLeft(firstArgument.start, `${context}, [ `); } code.appendLeft(this.arguments[this.arguments.length - 1].end, ' )'); } } } if (transforms.trailingFunctionCommas && this.arguments.length) { removeTrailingComma(code, this.arguments[this.arguments.length - 1].end); } super.transpile(code, transforms); } } buble-0.19.8/src/program/types/ClassBody.js000066400000000000000000000160701350705536200205370ustar00rootroot00000000000000import CompileError from '../../utils/CompileError.js'; import Node from '../Node.js'; import { findIndex } from '../../utils/array.js'; import reserved from '../../utils/reserved.js'; // TODO this code is pretty wild, tidy it up export default class ClassBody extends Node { transpile(code, transforms, inFunctionExpression, superName) { if (transforms.classes) { const name = this.parent.name; const indentStr = code.getIndentString(); const i0 = this.getIndentation() + (inFunctionExpression ? indentStr : ''); const i1 = i0 + indentStr; const constructorIndex = findIndex( this.body, node => node.kind === 'constructor' ); const constructor = this.body[constructorIndex]; let introBlock = ''; let outroBlock = ''; if (this.body.length) { code.remove(this.start, this.body[0].start); code.remove(this.body[this.body.length - 1].end, this.end); } else { code.remove(this.start, this.end); } if (constructor) { constructor.value.body.isConstructorBody = true; const previousMethod = this.body[constructorIndex - 1]; const nextMethod = this.body[constructorIndex + 1]; // ensure constructor is first if (constructorIndex > 0) { code.remove(previousMethod.end, constructor.start); code.move( constructor.start, nextMethod ? nextMethod.start : this.end - 1, this.body[0].start ); } if (!inFunctionExpression) code.appendLeft(constructor.end, ';'); } const namedFunctions = this.program.options.namedFunctionExpressions !== false; const namedConstructor = namedFunctions || this.parent.superClass || this.parent.type !== 'ClassDeclaration'; if (this.parent.superClass) { let inheritanceBlock = `if ( ${superName} ) ${name}.__proto__ = ${ superName };\n${i0}${name}.prototype = Object.create( ${superName} && ${ superName }.prototype );\n${i0}${name}.prototype.constructor = ${name};`; if (constructor) { introBlock += `\n\n${i0}` + inheritanceBlock; } else { const fn = `function ${name} () {` + (superName ? `\n${i1}${superName}.apply(this, arguments);\n${i0}}` : `}`) + (inFunctionExpression ? '' : ';') + (this.body.length ? `\n\n${i0}` : ''); inheritanceBlock = fn + inheritanceBlock; introBlock += inheritanceBlock + `\n\n${i0}`; } } else if (!constructor) { let fn = 'function ' + (namedConstructor ? name + ' ' : '') + '() {}'; if (this.parent.type === 'ClassDeclaration') fn += ';'; if (this.body.length) fn += `\n\n${i0}`; introBlock += fn; } const scope = this.findScope(false); const prototypeGettersAndSetters = []; const staticGettersAndSetters = []; let prototypeAccessors; let staticAccessors; this.body.forEach((method, i) => { if ((method.kind === 'get' || method.kind === 'set') && transforms.getterSetter) { CompileError.missingTransform("getters and setters", "getterSetter", method); } if (method.kind === 'constructor') { const constructorName = namedConstructor ? ' ' + name : ''; code.overwrite( method.key.start, method.key.end, `function${constructorName}` ); return; } if (method.static) { const len = code.original[method.start + 6] == ' ' ? 7 : 6; code.remove(method.start, method.start + len); } const isAccessor = method.kind !== 'method'; let lhs; let methodName = method.key.name; if ( reserved[methodName] || method.value.body.scope.references[methodName] ) { methodName = scope.createIdentifier(methodName); } // when method name is a string or a number let's pretend it's a computed method let fake_computed = false; if (!method.computed && method.key.type === 'Literal') { fake_computed = true; method.computed = true; } if (isAccessor) { if (method.computed) { throw new Error( 'Computed accessor properties are not currently supported' ); } code.remove(method.start, method.key.start); if (method.static) { if (!~staticGettersAndSetters.indexOf(method.key.name)) staticGettersAndSetters.push(method.key.name); if (!staticAccessors) staticAccessors = scope.createIdentifier('staticAccessors'); lhs = `${staticAccessors}`; } else { if (!~prototypeGettersAndSetters.indexOf(method.key.name)) prototypeGettersAndSetters.push(method.key.name); if (!prototypeAccessors) prototypeAccessors = scope.createIdentifier('prototypeAccessors'); lhs = `${prototypeAccessors}`; } } else { lhs = method.static ? `${name}` : `${name}.prototype`; } if (!method.computed) lhs += '.'; const insertNewlines = (constructorIndex > 0 && i === constructorIndex + 1) || (i === 0 && constructorIndex === this.body.length - 1); if (insertNewlines) lhs = `\n\n${i0}${lhs}`; let c = method.key.end; if (method.computed) { if (fake_computed) { code.prependRight(method.key.start, '['); code.appendLeft(method.key.end, ']'); } else { while (code.original[c] !== ']') c += 1; c += 1; } } const funcName = method.computed || isAccessor || !namedFunctions ? '' : `${methodName} `; const rhs = (isAccessor ? `.${method.kind}` : '') + ` = ${method.value.async ? 'async ' : ''}function` + (method.value.generator ? '* ' : ' ') + funcName; code.remove(c, method.value.start); code.prependRight(method.value.start, rhs); code.appendLeft(method.end, ';'); if (method.value.generator) code.remove(method.start, method.key.start); let start = method.key.start; if (method.computed && !fake_computed) { while (code.original[start] != '[') { --start; } } if (method.start < start) { code.overwrite(method.start, start, lhs); } else { code.prependRight(method.start, lhs); } }); if (prototypeGettersAndSetters.length || staticGettersAndSetters.length) { const intro = []; const outro = []; if (prototypeGettersAndSetters.length) { intro.push( `var ${prototypeAccessors} = { ${prototypeGettersAndSetters .map(name => `${name}: { configurable: true }`) .join(',')} };` ); outro.push( `Object.defineProperties( ${name}.prototype, ${ prototypeAccessors } );` ); } if (staticGettersAndSetters.length) { intro.push( `var ${staticAccessors} = { ${staticGettersAndSetters .map(name => `${name}: { configurable: true }`) .join(',')} };` ); outro.push(`Object.defineProperties( ${name}, ${staticAccessors} );`); } if (constructor) introBlock += `\n\n${i0}`; introBlock += intro.join(`\n${i0}`); if (!constructor) introBlock += `\n\n${i0}`; outroBlock += `\n\n${i0}` + outro.join(`\n${i0}`); } if (constructor) { code.appendLeft(constructor.end, introBlock); } else { code.prependRight(this.start, introBlock); } code.appendLeft(this.end, outroBlock); } super.transpile(code, transforms); } } buble-0.19.8/src/program/types/ClassDeclaration.js000066400000000000000000000044331350705536200220670ustar00rootroot00000000000000import Node from '../Node.js'; import deindent from '../../utils/deindent.js'; export default class ClassDeclaration extends Node { initialise(transforms) { if (this.id) { this.name = this.id.name; this.findScope(true).addDeclaration(this.id, 'class'); } else { this.name = this.findScope(true).createIdentifier("defaultExport"); } super.initialise(transforms); } transpile(code, transforms) { if (transforms.classes) { if (!this.superClass) deindent(this.body, code); const superName = this.superClass && (this.superClass.name || 'superclass'); const i0 = this.getIndentation(); const i1 = i0 + code.getIndentString(); // if this is an export default statement, we have to move the export to // after the declaration, because `export default var Foo = ...` is illegal const isExportDefaultDeclaration = this.parent.type === 'ExportDefaultDeclaration'; if (isExportDefaultDeclaration) { code.remove(this.parent.start, this.start); } let c = this.start; if (this.id) { code.overwrite(c, this.id.start, 'var '); c = this.id.end; } else { code.prependLeft(c, `var ${this.name}`); } if (this.superClass) { if (this.superClass.end === this.body.start) { code.remove(c, this.superClass.start); code.appendLeft(c, ` = /*@__PURE__*/(function (${superName}) {\n${i1}`); } else { code.overwrite(c, this.superClass.start, ' = '); code.overwrite( this.superClass.end, this.body.start, `/*@__PURE__*/(function (${superName}) {\n${i1}` ); } } else { if (c === this.body.start) { code.appendLeft(c, ' = '); } else { code.overwrite(c, this.body.start, ' = '); } } this.body.transpile(code, transforms, !!this.superClass, superName); const syntheticDefaultExport = isExportDefaultDeclaration ? `\n\n${i0}export default ${this.name};` : ''; if (this.superClass) { code.appendLeft(this.end, `\n\n${i1}return ${this.name};\n${i0}}(`); code.move(this.superClass.start, this.superClass.end, this.end); code.prependRight(this.end, `));${syntheticDefaultExport}`); } else if (syntheticDefaultExport) { code.prependRight(this.end, syntheticDefaultExport); } } else { this.body.transpile(code, transforms, false, null); } } } buble-0.19.8/src/program/types/ClassExpression.js000066400000000000000000000027521350705536200220030ustar00rootroot00000000000000import Node from '../Node.js'; export default class ClassExpression extends Node { initialise(transforms) { this.name = (this.id ? this.id.name : this.parent.type === 'VariableDeclarator' ? this.parent.id.name : this.parent.type !== 'AssignmentExpression' ? null : this.parent.left.type === 'Identifier' ? this.parent.left.name : this.parent.left.type === 'MemberExpression' ? this.parent.left.property.name : null) || this.findScope(true).createIdentifier('anonymous'); super.initialise(transforms); } transpile(code, transforms) { if (transforms.classes) { const superName = this.superClass && (this.superClass.name || 'superclass'); const i0 = this.getIndentation(); const i1 = i0 + code.getIndentString(); if (this.superClass) { code.remove(this.start, this.superClass.start); code.remove(this.superClass.end, this.body.start); code.appendRight(this.start, `/*@__PURE__*/(function (${superName}) {\n${i1}`); } else { code.overwrite(this.start, this.body.start, `/*@__PURE__*/(function () {\n${i1}`); } this.body.transpile(code, transforms, true, superName); let superClass = ''; if (this.superClass) { superClass = code.slice(this.superClass.start, this.superClass.end); code.remove(this.superClass.start, this.superClass.end); } code.appendLeft(this.end, `\n\n${i1}return ${this.name};\n${i0}}(${superClass}))`); } else { this.body.transpile(code, transforms, false); } } } buble-0.19.8/src/program/types/ContinueStatement.js000066400000000000000000000010051350705536200223150ustar00rootroot00000000000000import Node from '../Node.js'; import CompileError from '../../utils/CompileError.js'; import { loopStatement } from '../../utils/patterns.js'; export default class ContinueStatement extends Node { transpile(code) { const loop = this.findNearest(loopStatement); if (loop.shouldRewriteAsFunction) { if (this.label) throw new CompileError( 'Labels are not currently supported in a loop with locally-scoped variables', this ); code.overwrite(this.start, this.start + 8, 'return'); } } } buble-0.19.8/src/program/types/ExportDefaultDeclaration.js000066400000000000000000000004651350705536200236110ustar00rootroot00000000000000import Node from '../Node.js'; import CompileError from '../../utils/CompileError.js'; export default class ExportDefaultDeclaration extends Node { initialise(transforms) { if (transforms.moduleExport) CompileError.missingTransform("export", "moduleExport", this); super.initialise(transforms); } } buble-0.19.8/src/program/types/ExportNamedDeclaration.js000066400000000000000000000004631350705536200232470ustar00rootroot00000000000000import Node from '../Node.js'; import CompileError from '../../utils/CompileError.js'; export default class ExportNamedDeclaration extends Node { initialise(transforms) { if (transforms.moduleExport) CompileError.missingTransform("export", "moduleExport", this); super.initialise(transforms); } } buble-0.19.8/src/program/types/ForInStatement.js000066400000000000000000000036171350705536200215610ustar00rootroot00000000000000import LoopStatement from './shared/LoopStatement.js'; import destructure from '../../utils/destructure.js'; import extractNames from '../extractNames.js'; export default class ForInStatement extends LoopStatement { findScope(functionScope) { return functionScope || !this.createdScope ? this.parent.findScope(functionScope) : this.body.scope; } transpile(code, transforms) { const hasDeclaration = this.left.type === 'VariableDeclaration'; if (this.shouldRewriteAsFunction) { // which variables are declared in the init statement? const names = hasDeclaration ? this.left.declarations.map(declarator => extractNames(declarator.id)) : []; this.args = names.map( name => (name in this.aliases ? this.aliases[name].outer : name) ); this.params = names.map( name => (name in this.aliases ? this.aliases[name].inner : name) ); } super.transpile(code, transforms); const maybePattern = hasDeclaration ? this.left.declarations[0].id : this.left; if (maybePattern.type !== 'Identifier') { this.destructurePattern(code, maybePattern, hasDeclaration); } } destructurePattern(code, pattern, isDeclaration) { const scope = this.findScope(true); const i0 = this.getIndentation(); const i1 = i0 + code.getIndentString(); const ref = scope.createIdentifier('ref'); const bodyStart = this.body.body.length ? this.body.body[0].start : this.body.start + 1; code.move(pattern.start, pattern.end, bodyStart); code.prependRight(pattern.end, isDeclaration ? ref : `var ${ref}`); const statementGenerators = []; destructure( code, id => scope.createIdentifier(id), ({ name }) => scope.resolveName(name), pattern, ref, false, statementGenerators ); let suffix = `;\n${i1}`; statementGenerators.forEach((fn, i) => { if (i === statementGenerators.length - 1) { suffix = `;\n\n${i1}`; } fn(bodyStart, '', suffix); }); } } buble-0.19.8/src/program/types/ForOfStatement.js000066400000000000000000000051501350705536200215510ustar00rootroot00000000000000import LoopStatement from './shared/LoopStatement.js'; import CompileError from '../../utils/CompileError.js'; import destructure from '../../utils/destructure.js'; export default class ForOfStatement extends LoopStatement { initialise(transforms) { if (transforms.forOf && !transforms.dangerousForOf) CompileError.missingTransform("for-of statements", "forOf", this, "dangerousForOf"); if (this.await && transforms.asyncAwait) CompileError.missingTransform("for-await-of statements", "asyncAwait", this); super.initialise(transforms); } transpile(code, transforms) { super.transpile(code, transforms); if (!transforms.dangerousForOf) return; // edge case (#80) if (!this.body.body[0]) { if ( this.left.type === 'VariableDeclaration' && this.left.kind === 'var' ) { code.remove(this.start, this.left.start); code.appendLeft(this.left.end, ';'); code.remove(this.left.end, this.end); } else { code.remove(this.start, this.end); } return; } const scope = this.findScope(true); const i0 = this.getIndentation(); const i1 = i0 + code.getIndentString(); const key = scope.createIdentifier('i'); const list = scope.createIdentifier('list'); if (this.body.synthetic) { code.prependRight(this.left.start, `{\n${i1}`); code.appendLeft(this.body.body[0].end, `\n${i0}}`); } const bodyStart = this.body.body[0].start; code.remove(this.left.end, this.right.start); code.move(this.left.start, this.left.end, bodyStart); code.prependRight(this.right.start, `var ${key} = 0, ${list} = `); code.appendLeft(this.right.end, `; ${key} < ${list}.length; ${key} += 1`); const isDeclaration = this.left.type === 'VariableDeclaration'; const maybeDestructuring = isDeclaration ? this.left.declarations[0].id : this.left; if (maybeDestructuring.type !== 'Identifier') { const statementGenerators = []; const ref = scope.createIdentifier('ref'); destructure( code, id => scope.createIdentifier(id), ({ name }) => scope.resolveName(name), maybeDestructuring, ref, !isDeclaration, statementGenerators ); let suffix = `;\n${i1}`; statementGenerators.forEach((fn, i) => { if (i === statementGenerators.length - 1) { suffix = `;\n\n${i1}`; } fn(bodyStart, '', suffix); }); if (isDeclaration) { code.appendLeft(this.left.start + this.left.kind.length + 1, ref); code.appendLeft(this.left.end, ` = ${list}[${key}];\n${i1}`); } else { code.appendLeft(this.left.end, `var ${ref} = ${list}[${key}];\n${i1}`); } } else { code.appendLeft(this.left.end, ` = ${list}[${key}];\n\n${i1}`); } } } buble-0.19.8/src/program/types/ForStatement.js000066400000000000000000000025251350705536200212670ustar00rootroot00000000000000import LoopStatement from './shared/LoopStatement.js'; import extractNames from '../extractNames.js'; export default class ForStatement extends LoopStatement { findScope(functionScope) { return functionScope || !this.createdScope ? this.parent.findScope(functionScope) : this.body.scope; } transpile(code, transforms) { const i1 = this.getIndentation() + code.getIndentString(); if (this.shouldRewriteAsFunction) { // which variables are declared in the init statement? const names = this.init.type === 'VariableDeclaration' ? this.init.declarations.map(declarator => extractNames(declarator.id)) : []; const aliases = this.aliases; this.args = names.map( name => (name in this.aliases ? this.aliases[name].outer : name) ); this.params = names.map( name => (name in this.aliases ? this.aliases[name].inner : name) ); const updates = Object.keys(this.reassigned).map( name => `${aliases[name].outer} = ${aliases[name].inner};` ); if (updates.length) { if (this.body.synthetic) { code.appendLeft(this.body.body[0].end, `; ${updates.join(` `)}`); } else { const lastStatement = this.body.body[this.body.body.length - 1]; code.appendLeft( lastStatement.end, `\n\n${i1}${updates.join(`\n${i1}`)}` ); } } } super.transpile(code, transforms); } } buble-0.19.8/src/program/types/FunctionDeclaration.js000066400000000000000000000015111350705536200226010ustar00rootroot00000000000000import Node from '../Node.js'; import CompileError from '../../utils/CompileError.js'; import removeTrailingComma from '../../utils/removeTrailingComma.js'; export default class FunctionDeclaration extends Node { initialise(transforms) { if (this.generator && transforms.generator) { CompileError.missingTransform("generators", "generator", this); } if (this.async && transforms.asyncAwait) { CompileError.missingTransform("async functions", "asyncAwait", this); } this.body.createScope(); if (this.id) { this.findScope(true).addDeclaration(this.id, 'function'); } super.initialise(transforms); } transpile(code, transforms) { super.transpile(code, transforms); if (transforms.trailingFunctionCommas && this.params.length) { removeTrailingComma(code, this.params[this.params.length - 1].end); } } } buble-0.19.8/src/program/types/FunctionExpression.js000066400000000000000000000041161350705536200225170ustar00rootroot00000000000000import Node from '../Node.js'; import CompileError from '../../utils/CompileError.js'; import removeTrailingComma from '../../utils/removeTrailingComma.js'; export default class FunctionExpression extends Node { initialise(transforms) { if (this.generator && transforms.generator) { CompileError.missingTransform("generators", "generator", this); } if (this.async && transforms.asyncAwait) { CompileError.missingTransform("async functions", "asyncAwait", this); } this.body.createScope(); if (this.id) { // function expression IDs belong to the child scope... this.body.scope.addDeclaration(this.id, 'function'); } super.initialise(transforms); const parent = this.parent; let methodName; if ( transforms.conciseMethodProperty && parent.type === 'Property' && parent.kind === 'init' && parent.method && parent.key.type === 'Identifier' ) { // object literal concise method methodName = parent.key.name; } else if ( transforms.classes && parent.type === 'MethodDefinition' && parent.kind === 'method' && parent.key.type === 'Identifier' ) { // method definition in a class methodName = parent.key.name; } else if (this.id && this.id.type === 'Identifier') { // naked function expression methodName = this.id.alias || this.id.name; } if (methodName) { for (const param of this.params) { if (param.type === 'Identifier' && methodName === param.name) { // workaround for Safari 9/WebKit bug: // https://gitlab.com/Rich-Harris/buble/issues/154 // change parameter name when same as method name const scope = this.body.scope; const declaration = scope.declarations[methodName]; const alias = scope.createIdentifier(methodName); param.alias = alias; for (const identifier of declaration.instances) { identifier.alias = alias; } break; } } } } transpile(code, transforms) { super.transpile(code, transforms); if (transforms.trailingFunctionCommas && this.params.length) { removeTrailingComma(code, this.params[this.params.length - 1].end); } } } buble-0.19.8/src/program/types/Identifier.js000066400000000000000000000025221350705536200207330ustar00rootroot00000000000000import Node from '../Node.js'; import isReference from '../../utils/isReference.js'; import { loopStatement } from '../../utils/patterns.js'; export default class Identifier extends Node { findScope(functionScope) { if (this.parent.params && ~this.parent.params.indexOf(this)) { return this.parent.body.scope; } if (this.parent.type === 'FunctionExpression' && this === this.parent.id) { return this.parent.body.scope; } return this.parent.findScope(functionScope); } initialise(transforms) { if (isReference(this, this.parent)) { if ( transforms.arrow && this.name === 'arguments' && !this.findScope(false).contains(this.name) ) { const lexicalBoundary = this.findLexicalBoundary(); const arrowFunction = this.findNearest('ArrowFunctionExpression'); const loop = this.findNearest(loopStatement); if (arrowFunction && arrowFunction.depth > lexicalBoundary.depth) { this.alias = lexicalBoundary.getArgumentsAlias(); } if ( loop && loop.body.contains(this) && loop.depth > lexicalBoundary.depth ) { this.alias = lexicalBoundary.getArgumentsAlias(); } } this.findScope(false).addReference(this); } } transpile(code) { if (this.alias) { code.overwrite(this.start, this.end, this.alias, { storeName: true, contentOnly: true }); } } } buble-0.19.8/src/program/types/IfStatement.js000066400000000000000000000013661350705536200211010ustar00rootroot00000000000000import Node from '../Node.js'; export default class IfStatement extends Node { initialise(transforms) { super.initialise(transforms); } transpile(code, transforms) { if ( this.consequent.type !== 'BlockStatement' || (this.consequent.type === 'BlockStatement' && this.consequent.synthetic) ) { code.appendLeft(this.consequent.start, '{ '); code.prependRight(this.consequent.end, ' }'); } if ( this.alternate && this.alternate.type !== 'IfStatement' && (this.alternate.type !== 'BlockStatement' || (this.alternate.type === 'BlockStatement' && this.alternate.synthetic)) ) { code.appendLeft(this.alternate.start, '{ '); code.prependRight(this.alternate.end, ' }'); } super.transpile(code, transforms); } } buble-0.19.8/src/program/types/Import.js000066400000000000000000000004751350705536200201300ustar00rootroot00000000000000import Node from '../Node.js'; import CompileError from '../../utils/CompileError.js'; export default class Import extends Node { initialise(transforms) { if (transforms.moduleImport) { CompileError.missingTransform("dynamic import expressions", "moduleImport", this); } super.initialise(transforms); } } buble-0.19.8/src/program/types/ImportDeclaration.js000066400000000000000000000004561350705536200222750ustar00rootroot00000000000000import Node from '../Node.js'; import CompileError from '../../utils/CompileError.js'; export default class ImportDeclaration extends Node { initialise(transforms) { if (transforms.moduleImport) CompileError.missingTransform("import", "moduleImport", this); super.initialise(transforms); } } buble-0.19.8/src/program/types/ImportDefaultSpecifier.js000066400000000000000000000003271350705536200232630ustar00rootroot00000000000000import Node from '../Node.js'; export default class ImportDefaultSpecifier extends Node { initialise(transforms) { this.findScope(true).addDeclaration(this.local, 'import'); super.initialise(transforms); } } buble-0.19.8/src/program/types/ImportSpecifier.js000066400000000000000000000003201350705536200217470ustar00rootroot00000000000000import Node from '../Node.js'; export default class ImportSpecifier extends Node { initialise(transforms) { this.findScope(true).addDeclaration(this.local, 'import'); super.initialise(transforms); } } buble-0.19.8/src/program/types/JSXAttribute.js000066400000000000000000000010241350705536200211750ustar00rootroot00000000000000import Node from '../Node.js'; const hasDashes = val => /-/.test(val); const formatKey = key => (hasDashes(key) ? `'${key}'` : key); const formatVal = val => (val ? '' : 'true'); export default class JSXAttribute extends Node { transpile(code, transforms) { const { start, name } = this.name; // Overwrite equals sign if value is present. const end = this.value ? this.value.start : this.name.end; code.overwrite(start, end, `${formatKey(name)}: ${formatVal(this.value)}`); super.transpile(code, transforms); } } buble-0.19.8/src/program/types/JSXClosingElement.js000066400000000000000000000012711350705536200221460ustar00rootroot00000000000000import Node from '../Node.js'; function containsNewLine(node) { return ( node.type === 'JSXText' && !/\S/.test(node.value) && /\n/.test(node.value) ); } export default class JSXClosingElement extends Node { transpile(code) { let spaceBeforeParen = true; const lastChild = this.parent.children[this.parent.children.length - 1]; // omit space before closing paren if // a) this is on a separate line, or // b) there are no children but there are attributes if ( (lastChild && containsNewLine(lastChild)) || this.parent.openingElement.attributes.length ) { spaceBeforeParen = false; } code.overwrite(this.start, this.end, spaceBeforeParen ? ' )' : ')'); } } buble-0.19.8/src/program/types/JSXClosingFragment.js000066400000000000000000000010671350705536200223230ustar00rootroot00000000000000import Node from '../Node.js'; function containsNewLine(node) { return ( node.type === 'JSXText' && !/\S/.test(node.value) && /\n/.test(node.value) ); } export default class JSXClosingFragment extends Node { transpile(code) { let spaceBeforeParen = true; const lastChild = this.parent.children[this.parent.children.length - 1]; // omit space before closing paren if this is on a separate line if (lastChild && containsNewLine(lastChild)) { spaceBeforeParen = false; } code.overwrite(this.start, this.end, spaceBeforeParen ? ' )' : ')'); } } buble-0.19.8/src/program/types/JSXElement.js000066400000000000000000000026201350705536200206260ustar00rootroot00000000000000import Node from '../Node.js'; function normalise(str, removeTrailingWhitespace) { str = str.replace(/\u00a0/g, ' '); if (removeTrailingWhitespace && /\n/.test(str)) { str = str.replace(/\s+$/, ''); } str = str .replace(/^\n\r?\s+/, '') // remove leading newline + space .replace(/\s*\n\r?\s*/gm, ' '); // replace newlines with spaces // TODO prefer single quotes? return JSON.stringify(str); } export default class JSXElement extends Node { transpile(code, transforms) { super.transpile(code, transforms); const children = this.children.filter(child => { if (child.type !== 'JSXText') return true; // remove whitespace-only literals, unless on a single line return /\S/.test(child.raw) || !/\n/.test(child.raw); }); if (children.length) { let c = (this.openingElement || this.openingFragment).end; let i; for (i = 0; i < children.length; i += 1) { const child = children[i]; if ( child.type === 'JSXExpressionContainer' && child.expression.type === 'JSXEmptyExpression' ) { // empty block is a no op } else { const tail = code.original[c] === '\n' && child.type !== 'JSXText' ? '' : ' '; code.appendLeft(c, `,${tail}`); } if (child.type === 'JSXText') { const str = normalise(child.value, i === children.length - 1); code.overwrite(child.start, child.end, str); } c = child.end; } } } } buble-0.19.8/src/program/types/JSXExpressionContainer.js000066400000000000000000000004051350705536200232360ustar00rootroot00000000000000import Node from '../Node.js'; export default class JSXExpressionContainer extends Node { transpile(code, transforms) { code.remove(this.start, this.expression.start); code.remove(this.expression.end, this.end); super.transpile(code, transforms); } } buble-0.19.8/src/program/types/JSXFragment.js000066400000000000000000000001431350705536200207760ustar00rootroot00000000000000import JSXElement from './JSXElement.js'; export default class JSXFragment extends JSXElement { } buble-0.19.8/src/program/types/JSXOpeningElement.js000066400000000000000000000043601350705536200221510ustar00rootroot00000000000000import Node from '../Node.js'; import CompileError from '../../utils/CompileError.js'; export default class JSXOpeningElement extends Node { transpile(code, transforms) { super.transpile(code, transforms); code.overwrite(this.start, this.name.start, `${this.program.jsx}( `); const html = this.name.type === 'JSXIdentifier' && this.name.name[0] === this.name.name[0].toLowerCase(); if (html) code.prependRight(this.name.start, `'`); const len = this.attributes.length; let c = this.name.end; if (len) { let i; let hasSpread = false; for (i = 0; i < len; i += 1) { if (this.attributes[i].type === 'JSXSpreadAttribute') { hasSpread = true; break; } } c = this.attributes[0].end; for (i = 0; i < len; i += 1) { const attr = this.attributes[i]; if (i > 0) { if (attr.start === c) code.prependRight(c, ', '); else code.overwrite(c, attr.start, ', '); } if (hasSpread && attr.type !== 'JSXSpreadAttribute') { const lastAttr = this.attributes[i - 1]; const nextAttr = this.attributes[i + 1]; if (!lastAttr || lastAttr.type === 'JSXSpreadAttribute') { code.prependRight(attr.start, '{ '); } if (!nextAttr || nextAttr.type === 'JSXSpreadAttribute') { code.appendLeft(attr.end, ' }'); } } c = attr.end; } let after; let before; if (hasSpread) { if (len === 1) { before = html ? `',` : ','; } else { if (!this.program.options.objectAssign) { throw new CompileError( "Mixed JSX attributes ending in spread requires specified objectAssign option with 'Object.assign' or polyfill helper.", this ); } before = html ? `', ${this.program.options.objectAssign}({},` : `, ${this.program.options.objectAssign}({},`; after = ')'; } } else { before = html ? `', {` : ', {'; after = ' }'; } code.prependRight(this.name.end, before); if (after) { code.appendLeft(this.attributes[len - 1].end, after); } } else { code.appendLeft(this.name.end, html ? `', null` : `, null`); c = this.name.end; } if (this.selfClosing) { code.overwrite(c, this.end, this.attributes.length ? `)` : ` )`); } else { code.remove(c, this.end); } } } buble-0.19.8/src/program/types/JSXOpeningFragment.js000066400000000000000000000003211350705536200223140ustar00rootroot00000000000000import Node from '../Node.js'; export default class JSXOpeningFragment extends Node { transpile(code) { code.overwrite(this.start, this.end, `${this.program.jsx}( ${this.program.jsxFragment}, null`); } } buble-0.19.8/src/program/types/JSXSpreadAttribute.js000066400000000000000000000003751350705536200223440ustar00rootroot00000000000000import Node from '../Node.js'; export default class JSXSpreadAttribute extends Node { transpile(code, transforms) { code.remove(this.start, this.argument.start); code.remove(this.argument.end, this.end); super.transpile(code, transforms); } } buble-0.19.8/src/program/types/Literal.js000066400000000000000000000023551350705536200202510ustar00rootroot00000000000000import Node from '../Node.js'; import CompileError from '../../utils/CompileError.js'; import rewritePattern from 'regexpu-core'; const nonAsciiLsOrPs = /[\u2028-\u2029]/g; export default class Literal extends Node { initialise() { if (typeof this.value === 'string') { this.program.indentExclusionElements.push(this); } } transpile(code, transforms) { if (transforms.numericLiteral) { if (this.raw.match(/^0[bo]/i)) { code.overwrite(this.start, this.end, String(this.value), { storeName: true, contentOnly: true }); } } if (this.regex) { const { pattern, flags } = this.regex; if (transforms.stickyRegExp && /y/.test(flags)) CompileError.missingTransform('the regular expression sticky flag', 'stickyRegExp', this); if (transforms.unicodeRegExp && /u/.test(flags)) { code.overwrite( this.start, this.end, `/${rewritePattern(pattern, flags)}/${flags.replace('u', '')}`, { contentOnly: true } ); } } else if (typeof this.value === "string" && this.value.match(nonAsciiLsOrPs)) { code.overwrite( this.start, this.end, this.raw.replace(nonAsciiLsOrPs, m => m == '\u2028' ? '\\u2028' : '\\u2029'), { contentOnly: true } ); } } } buble-0.19.8/src/program/types/MemberExpression.js000066400000000000000000000006061350705536200221410ustar00rootroot00000000000000import Node from '../Node.js'; import reserved from '../../utils/reserved.js'; export default class MemberExpression extends Node { transpile(code, transforms) { if (transforms.reservedProperties && reserved[this.property.name]) { code.overwrite(this.object.end, this.property.start, `['`); code.appendLeft(this.property.end, `']`); } super.transpile(code, transforms); } } buble-0.19.8/src/program/types/NewExpression.js000066400000000000000000000030211350705536200214550ustar00rootroot00000000000000import Node from '../Node.js'; import spread, { isArguments, inlineSpreads } from '../../utils/spread.js'; import removeTrailingComma from '../../utils/removeTrailingComma.js'; export default class NewExpression extends Node { initialise(transforms) { if (transforms.spreadRest && this.arguments.length) { const lexicalBoundary = this.findLexicalBoundary(); let i = this.arguments.length; while (i--) { const arg = this.arguments[i]; if (arg.type === 'SpreadElement' && isArguments(arg.argument)) { this.argumentsArrayAlias = lexicalBoundary.getArgumentsArrayAlias(); break; } } } super.initialise(transforms); } transpile(code, transforms) { super.transpile(code, transforms); if (transforms.spreadRest && this.arguments.length) { inlineSpreads(code, this, this.arguments); // this.arguments.length may have changed, must retest. } if (transforms.spreadRest && this.arguments.length) { const firstArgument = this.arguments[0]; const isNew = true; const hasSpreadElements = spread( code, this.arguments, firstArgument.start, this.argumentsArrayAlias, isNew ); if (hasSpreadElements) { code.prependRight( this.start + 'new'.length, ' (Function.prototype.bind.apply(' ); code.overwrite( this.callee.end, firstArgument.start, ', [ null ].concat( ' ); code.appendLeft(this.end, ' ))'); } } if (this.arguments.length) { removeTrailingComma(code, this.arguments[this.arguments.length - 1].end); } } } buble-0.19.8/src/program/types/ObjectExpression.js000066400000000000000000000211661350705536200221440ustar00rootroot00000000000000import Node from '../Node.js'; import CompileError from '../../utils/CompileError.js'; export default class ObjectExpression extends Node { transpile(code, transforms) { super.transpile(code, transforms); let firstPropertyStart = this.start + 1; let spreadPropertyCount = 0; let computedPropertyCount = 0; let firstSpreadProperty = null; let firstComputedProperty = null; for (let i = 0; i < this.properties.length; ++i) { const prop = this.properties[i]; if (prop.type === 'SpreadElement') { // First see if we can inline the spread, to save needing objectAssign. const argument = prop.argument; if ( argument.type === 'ObjectExpression' || ( argument.type === 'Literal' && typeof argument.value !== 'string' ) ) { if (argument.type === 'ObjectExpression' && argument.properties.length > 0) { // Strip the `...{` and the `}` with a possible trailing comma before it, // leaving just the possible trailing comma after it. code.remove(prop.start, argument.properties[0].start); code.remove(argument.properties[argument.properties.length - 1].end, prop.end); this.properties.splice(i, 1, ...argument.properties); i--; } else { // An empty object, boolean, null, undefined, number or regexp (but NOT // string) will spread to nothing, so just remove the element altogether, // including a possible trailing comma. code.remove(prop.start, i === this.properties.length - 1 ? prop.end : this.properties[i + 1].start); this.properties.splice(i, 1); i--; } } else { spreadPropertyCount += 1; if (firstSpreadProperty === null) firstSpreadProperty = i; } } else if (prop.computed && transforms.computedProperty) { computedPropertyCount += 1; if (firstComputedProperty === null) firstComputedProperty = i; } } if (spreadPropertyCount && !transforms.objectRestSpread && !(computedPropertyCount && transforms.computedProperty)) { spreadPropertyCount = 0; firstSpreadProperty = null; } else if (spreadPropertyCount) { if (!this.program.options.objectAssign) { throw new CompileError( "Object spread operator requires specified objectAssign option with 'Object.assign' or polyfill helper.", this ); } let i = this.properties.length; while (i--) { const prop = this.properties[i]; // enclose run of non-spread properties in curlies if (prop.type === 'Property' && !computedPropertyCount) { const lastProp = this.properties[i - 1]; const nextProp = this.properties[i + 1]; if (!lastProp || lastProp.type !== 'Property') { code.prependRight(prop.start, '{'); } if (!nextProp || nextProp.type !== 'Property') { code.appendLeft(prop.end, '}'); } } // Remove ellipsis on spread property if (prop.type === 'SpreadElement') { code.remove(prop.start, prop.argument.start); code.remove(prop.argument.end, prop.end); } } // wrap the whole thing in Object.assign firstPropertyStart = this.properties[0].start; if (!computedPropertyCount) { code.overwrite( this.start, firstPropertyStart, `${this.program.options.objectAssign}({}, ` ); code.overwrite( this.properties[this.properties.length - 1].end, this.end, ')' ); } else if (this.properties[0].type === 'SpreadElement') { code.overwrite( this.start, firstPropertyStart, `${this.program.options.objectAssign}({}, ` ); code.remove(this.end - 1, this.end); code.appendRight(this.end, ')'); } else { code.prependLeft(this.start, `${this.program.options.objectAssign}(`); code.appendRight(this.end, ')'); } } if (computedPropertyCount && transforms.computedProperty) { const i0 = this.getIndentation(); let isSimpleAssignment; let name; if ( this.parent.type === 'VariableDeclarator' && this.parent.parent.declarations.length === 1 && this.parent.id.type === 'Identifier' ) { isSimpleAssignment = true; name = this.parent.id.alias || this.parent.id.name; // TODO is this right? } else if ( this.parent.type === 'AssignmentExpression' && this.parent.parent.type === 'ExpressionStatement' && this.parent.left.type === 'Identifier' ) { isSimpleAssignment = true; name = this.parent.left.alias || this.parent.left.name; // TODO is this right? } else if ( this.parent.type === 'AssignmentPattern' && this.parent.left.type === 'Identifier' ) { isSimpleAssignment = true; name = this.parent.left.alias || this.parent.left.name; // TODO is this right? } if (spreadPropertyCount) isSimpleAssignment = false; // handle block scoping name = this.findScope(false).resolveName(name); const start = firstPropertyStart; const end = this.end; if (isSimpleAssignment) { // ??? } else { if ( firstSpreadProperty === null || firstComputedProperty < firstSpreadProperty ) { name = this.findScope(true).createDeclaration('obj'); code.prependRight(this.start, `( ${name} = `); } else name = null; // We don't actually need this variable } const len = this.properties.length; let lastComputedProp; let sawNonComputedProperty = false; let isFirst = true; for (let i = 0; i < len; i += 1) { const prop = this.properties[i]; let moveStart = i > 0 ? this.properties[i - 1].end : start; if ( prop.type === 'Property' && (prop.computed || (lastComputedProp && !spreadPropertyCount)) ) { if (i === 0) moveStart = this.start + 1; // Trim leading whitespace lastComputedProp = prop; if (!name) { name = this.findScope(true).createDeclaration('obj'); const propId = name + (prop.computed ? '' : '.'); code.appendRight(prop.start, `( ${name} = {}, ${propId}`); } else { const propId = (isSimpleAssignment ? `;\n${i0}${name}` : `, ${name}`) + (prop.key.type === 'Literal' || prop.computed ? '' : '.'); if (moveStart < prop.start) { code.overwrite(moveStart, prop.start, propId); } else { code.prependRight(prop.start, propId); } } let c = prop.key.end; if (prop.computed) { while (code.original[c] !== ']') c += 1; c += 1; } if (prop.key.type === 'Literal' && !prop.computed) { code.overwrite( prop.start, prop.value.start, '[' + code.slice(prop.start, prop.key.end) + '] = ' ); } else if (prop.shorthand || (prop.method && !prop.computed && transforms.conciseMethodProperty)) { // Replace : with = if Property::transpile inserted the : code.overwrite( prop.key.start, prop.key.end, code.slice(prop.key.start, prop.key.end).replace(/:/, ' =') ); } else { if (prop.value.start > c) code.remove(c, prop.value.start); code.prependLeft(c, ' = '); } // This duplicates behavior from Property::transpile which is disabled // for computed properties or if conciseMethodProperty is false if (prop.method && (prop.computed || !transforms.conciseMethodProperty)) { if (prop.value.generator) code.remove(prop.start, prop.key.start); code.prependRight(prop.value.start, `function${prop.value.generator ? '*' : ''} `); } } else if (prop.type === 'SpreadElement') { if (name && i > 0) { if (!lastComputedProp) { lastComputedProp = this.properties[i - 1]; } code.appendLeft(lastComputedProp.end, `, ${name} )`); lastComputedProp = null; name = null; } } else { if (!isFirst && spreadPropertyCount) { // We are in an Object.assign context, so we need to wrap regular properties code.prependRight(prop.start, '{'); code.appendLeft(prop.end, '}'); } sawNonComputedProperty = true; } if (isFirst && (prop.type === 'SpreadElement' || prop.computed)) { let beginEnd = sawNonComputedProperty ? this.properties[this.properties.length - 1].end : this.end - 1; // Trim trailing comma because it can easily become a leading comma which is illegal if (code.original[beginEnd] == ',') ++beginEnd; const closing = code.slice(beginEnd, end); code.prependLeft(moveStart, closing); code.remove(beginEnd, end); isFirst = false; } // Clean up some extranous whitespace let c = prop.end; if (i < len - 1 && !sawNonComputedProperty) { while (code.original[c] !== ',') c += 1; } else if (i == len - 1) c = this.end; if (prop.end != c) code.overwrite(prop.end, c, '', {contentOnly: true}); } if (!isSimpleAssignment && name) { code.appendLeft(lastComputedProp.end, `, ${name} )`); } } } } buble-0.19.8/src/program/types/Property.js000066400000000000000000000033151350705536200204760ustar00rootroot00000000000000import CompileError from '../../utils/CompileError.js'; import Node from '../Node.js'; import reserved from '../../utils/reserved.js'; export default class Property extends Node { initialise(transforms) { if ((this.kind === 'get' || this.kind === 'set') && transforms.getterSetter) { CompileError.missingTransform("getters and setters", "getterSetter", this); } super.initialise(transforms); } transpile(code, transforms) { super.transpile(code, transforms); if ( transforms.conciseMethodProperty && !this.computed && this.parent.type !== 'ObjectPattern' ) { if (this.shorthand) { code.prependRight(this.start, `${this.key.name}: `); } else if (this.method) { let name = ''; if (this.program.options.namedFunctionExpressions !== false) { if ( this.key.type === 'Literal' && typeof this.key.value === 'number' ) { name = ''; } else if (this.key.type === 'Identifier') { if ( reserved[this.key.name] || !/^[a-z_$][a-z0-9_$]*$/i.test(this.key.name) || this.value.body.scope.references[this.key.name] ) { name = this.findScope(true).createIdentifier(this.key.name); } else { name = this.key.name; } } else { name = this.findScope(true).createIdentifier(this.key.value); } name = ' ' + name; } if (this.start < this.key.start) code.remove(this.start, this.key.start); code.appendLeft( this.key.end, `: ${this.value.async ? 'async ' : ''}function${this.value.generator ? '*' : ''}${name}` ); } } if (transforms.reservedProperties && reserved[this.key.name]) { code.prependRight(this.key.start, `'`); code.appendLeft(this.key.end, `'`); } } } buble-0.19.8/src/program/types/ReturnStatement.js000066400000000000000000000016041350705536200220150ustar00rootroot00000000000000import Node from '../Node.js'; import { loopStatement } from '../../utils/patterns.js'; export default class ReturnStatement extends Node { initialise(transforms) { this.loop = this.findNearest(loopStatement); this.nearestFunction = this.findNearest(/Function/); if ( this.loop && (!this.nearestFunction || this.loop.depth > this.nearestFunction.depth) ) { this.loop.canReturn = true; this.shouldWrap = true; } if (this.argument) this.argument.initialise(transforms); } transpile(code, transforms) { const shouldWrap = this.shouldWrap && this.loop && this.loop.shouldRewriteAsFunction; if (this.argument) { if (shouldWrap) code.prependRight(this.argument.start, `{ v: `); this.argument.transpile(code, transforms); if (shouldWrap) code.appendLeft(this.argument.end, ` }`); } else if (shouldWrap) { code.appendLeft(this.start + 6, ' {}'); } } } buble-0.19.8/src/program/types/Super.js000066400000000000000000000046451350705536200177570ustar00rootroot00000000000000import Node from '../Node.js'; import CompileError from '../../utils/CompileError.js'; import { loopStatement } from '../../utils/patterns.js'; export default class Super extends Node { initialise(transforms) { if (transforms.classes) { this.method = this.findNearest('MethodDefinition'); if (!this.method) throw new CompileError('use of super outside class method', this); const parentClass = this.findNearest('ClassBody').parent; this.superClassName = parentClass.superClass && (parentClass.superClass.name || 'superclass'); if (!this.superClassName) throw new CompileError('super used in base class', this); this.isCalled = this.parent.type === 'CallExpression' && this === this.parent.callee; if (this.method.kind !== 'constructor' && this.isCalled) { throw new CompileError( 'super() not allowed outside class constructor', this ); } this.isMember = this.parent.type === 'MemberExpression'; if (!this.isCalled && !this.isMember) { throw new CompileError( 'Unexpected use of `super` (expected `super(...)` or `super.*`)', this ); } } if (transforms.arrow) { const lexicalBoundary = this.findLexicalBoundary(); const arrowFunction = this.findNearest('ArrowFunctionExpression'); const loop = this.findNearest(loopStatement); if (arrowFunction && arrowFunction.depth > lexicalBoundary.depth) { this.thisAlias = lexicalBoundary.getThisAlias(); } if ( loop && loop.body.contains(this) && loop.depth > lexicalBoundary.depth ) { this.thisAlias = lexicalBoundary.getThisAlias(); } } } transpile(code, transforms) { if (transforms.classes) { const expression = this.isCalled || this.method.static ? this.superClassName : `${this.superClassName}.prototype`; code.overwrite(this.start, this.end, expression, { storeName: true, contentOnly: true }); const callExpression = this.isCalled ? this.parent : this.parent.parent; if (callExpression && callExpression.type === 'CallExpression') { if (!this.noCall) { // special case – `super( ...args )` code.appendLeft(callExpression.callee.end, '.call'); } const thisAlias = this.thisAlias || 'this'; if (callExpression.arguments.length) { code.appendLeft(callExpression.arguments[0].start, `${thisAlias}, `); } else { code.appendLeft(callExpression.end - 1, `${thisAlias}`); } } } } } buble-0.19.8/src/program/types/TaggedTemplateExpression.js000066400000000000000000000032131350705536200236160ustar00rootroot00000000000000import Node from '../Node.js'; import CompileError from '../../utils/CompileError.js'; export default class TaggedTemplateExpression extends Node { initialise(transforms) { if ( transforms.templateString && !transforms.dangerousTaggedTemplateString ) { CompileError.missingTransform( "tagged template strings", "templateString", this, "dangerousTaggedTemplateString" ); } super.initialise(transforms); } transpile(code, transforms) { if (transforms.templateString && transforms.dangerousTaggedTemplateString) { const ordered = this.quasi.expressions .concat(this.quasi.quasis) .sort((a, b) => a.start - b.start); const program = this.program; const rootScope = program.body.scope; // insert strings at start const templateStrings = this.quasi.quasis.map(quasi => JSON.stringify(quasi.value.cooked) ).join(', '); let templateObject = this.program.templateLiteralQuasis[templateStrings]; if (!templateObject) { templateObject = rootScope.createIdentifier('templateObject'); code.prependLeft(this.program.prependAt, `var ${templateObject} = Object.freeze([${templateStrings}]);\n`); this.program.templateLiteralQuasis[templateStrings] = templateObject; } code.overwrite( this.tag.end, ordered[0].start, `(${templateObject}` ); let lastIndex = ordered[0].start; ordered.forEach(node => { if (node.type === 'TemplateElement') { code.remove(lastIndex, node.end); } else { code.overwrite(lastIndex, node.start, ', '); } lastIndex = node.end; }); code.overwrite(lastIndex, this.end, ')'); } super.transpile(code, transforms); } } buble-0.19.8/src/program/types/TemplateElement.js000066400000000000000000000002341350705536200217340ustar00rootroot00000000000000import Node from '../Node.js'; export default class TemplateElement extends Node { initialise() { this.program.indentExclusionElements.push(this); } } buble-0.19.8/src/program/types/TemplateLiteral.js000066400000000000000000000043401350705536200217410ustar00rootroot00000000000000import Node from '../Node.js'; export default class TemplateLiteral extends Node { transpile(code, transforms) { super.transpile(code, transforms); if ( transforms.templateString && this.parent.type !== 'TaggedTemplateExpression' ) { const ordered = this.expressions .concat(this.quasis) .sort((a, b) => a.start - b.start || a.end - b.end) .filter((node, i) => { // include all expressions if (node.type !== 'TemplateElement') return true; // include all non-empty strings if (node.value.raw) return true; // exclude all empty strings not at the head return !i; }); // special case – we may be able to skip the first element, // if it's the empty string, but only if the second and // third elements aren't both expressions (since they maybe // be numeric, and `1 + 2 + '3' === '33'`) if (ordered.length >= 3) { const [first, , third] = ordered; if ( first.type === 'TemplateElement' && first.value.raw === '' && third.type === 'TemplateElement' ) { ordered.shift(); } } const parenthesise = (this.quasis.length !== 1 || this.expressions.length !== 0) && this.parent.type !== 'TemplateLiteral' && this.parent.type !== 'AssignmentExpression' && this.parent.type !== 'AssignmentPattern' && this.parent.type !== 'VariableDeclarator' && (this.parent.type !== 'BinaryExpression' || this.parent.operator !== '+'); if (parenthesise) code.appendRight(this.start, '('); let lastIndex = this.start; ordered.forEach((node, i) => { let prefix = i === 0 ? (parenthesise ? '(' : '') : ' + '; if (node.type === 'TemplateElement') { code.overwrite( lastIndex, node.end, prefix + JSON.stringify(node.value.cooked) ); } else { const parenthesise = node.type !== 'Identifier'; // TODO other cases where it's safe if (parenthesise) prefix += '('; code.remove(lastIndex, node.start); if (prefix) code.prependRight(node.start, prefix); if (parenthesise) code.appendLeft(node.end, ')'); } lastIndex = node.end; }); if (parenthesise) code.appendLeft(lastIndex, ')'); code.overwrite(lastIndex, this.end, "", { contentOnly: true }); } } } buble-0.19.8/src/program/types/ThisExpression.js000066400000000000000000000016621350705536200216440ustar00rootroot00000000000000import Node from '../Node.js'; import { loopStatement } from '../../utils/patterns.js'; export default class ThisExpression extends Node { initialise(transforms) { const lexicalBoundary = this.findLexicalBoundary(); if (transforms.letConst) { // save all loops up to the lexical boundary in case we need // to alias them later for block-scoped declarations let node = this.findNearest(loopStatement); while (node && node.depth > lexicalBoundary.depth) { node.thisRefs.push(this); node = node.parent.findNearest(loopStatement); } } if (transforms.arrow) { const arrowFunction = this.findNearest('ArrowFunctionExpression'); if (arrowFunction && arrowFunction.depth > lexicalBoundary.depth) { this.alias = lexicalBoundary.getThisAlias(); } } } transpile(code) { if (this.alias) { code.overwrite(this.start, this.end, this.alias, { storeName: true, contentOnly: true }); } } } buble-0.19.8/src/program/types/UpdateExpression.js000066400000000000000000000016461350705536200221610ustar00rootroot00000000000000import Node from '../Node.js'; import checkConst from '../../utils/checkConst.js'; export default class UpdateExpression extends Node { initialise(transforms) { if (this.argument.type === 'Identifier') { const declaration = this.findScope(false).findDeclaration( this.argument.name ); // special case – https://gitlab.com/Rich-Harris/buble/issues/150 const statement = declaration && declaration.node.ancestor(3); if ( statement && statement.type === 'ForStatement' && statement.body.contains(this) ) { statement.reassigned[this.argument.name] = true; } } super.initialise(transforms); } transpile(code, transforms) { if (this.argument.type === 'Identifier') { // Do this check after everything has been initialized to find // shadowing declarations after this expression checkConst(this.argument, this.findScope(false)); } super.transpile(code, transforms); } } buble-0.19.8/src/program/types/VariableDeclaration.js000066400000000000000000000055051350705536200225500ustar00rootroot00000000000000import Node from '../Node.js'; import destructure from '../../utils/destructure.js'; import { loopStatement } from '../../utils/patterns.js'; export default class VariableDeclaration extends Node { initialise(transforms) { this.scope = this.findScope(this.kind === 'var'); this.declarations.forEach(declarator => declarator.initialise(transforms)); } transpile(code, transforms) { const i0 = this.getIndentation(); let kind = this.kind; if (transforms.letConst && kind !== 'var') { kind = 'var'; code.overwrite(this.start, this.start + this.kind.length, kind, { contentOnly: true, storeName: true }); } if (transforms.destructuring && this.parent.type !== 'ForOfStatement' && this.parent.type !== 'ForInStatement') { let c = this.start; let lastDeclaratorIsPattern; this.declarations.forEach((declarator, i) => { declarator.transpile(code, transforms); if (declarator.id.type === 'Identifier') { if (i > 0 && this.declarations[i - 1].id.type !== 'Identifier') { code.overwrite(c, declarator.id.start, `var `); } } else { const inline = loopStatement.test(this.parent.type); if (i === 0) { code.remove(c, declarator.id.start); } else { code.overwrite(c, declarator.id.start, `;\n${i0}`); } const simple = declarator.init.type === 'Identifier' && !declarator.init.rewritten; const name = simple ? (declarator.init.alias || declarator.init.name) : declarator.findScope(true).createIdentifier('ref'); c = declarator.start; const statementGenerators = []; if (simple) { code.remove(declarator.id.end, declarator.end); } else { statementGenerators.push((start, prefix, suffix) => { code.prependRight(declarator.id.end, `var ${name}`); code.appendLeft(declarator.init.end, `${suffix}`); code.move(declarator.id.end, declarator.end, start); }); } const scope = declarator.findScope(false); destructure( code, id => scope.createIdentifier(id), ({ name }) => scope.resolveName(name), declarator.id, name, inline, statementGenerators ); const prefix = inline ? 'var ' : ''; let suffix = inline ? `, ` : `;\n${i0}`; statementGenerators.forEach((fn, j) => { if ( i === this.declarations.length - 1 && j === statementGenerators.length - 1 ) { suffix = inline ? '' : ';'; } fn(declarator.start, j === 0 ? prefix : '', suffix); }); } c = declarator.end; lastDeclaratorIsPattern = declarator.id.type !== 'Identifier'; }); if (lastDeclaratorIsPattern && this.end > c) { code.overwrite(c, this.end, '', { contentOnly: true }); } } else { this.declarations.forEach(declarator => { declarator.transpile(code, transforms); }); } } } buble-0.19.8/src/program/types/VariableDeclarator.js000066400000000000000000000022001350705536200223700ustar00rootroot00000000000000import Node from '../Node.js'; export default class VariableDeclarator extends Node { initialise(transforms) { let kind = this.parent.kind; if (kind === 'let' && this.parent.parent.type === 'ForStatement') { kind = 'for.let'; // special case... } this.parent.scope.addDeclaration(this.id, kind); super.initialise(transforms); } transpile(code, transforms) { if (!this.init && transforms.letConst && this.parent.kind !== 'var') { const inLoop = this.findNearest( /Function|^For(In|Of)?Statement|^(?:Do)?WhileStatement/ ); if ( inLoop && !/Function/.test(inLoop.type) && !this.isLeftDeclaratorOfLoop() ) { code.appendLeft(this.id.end, ' = (void 0)'); } } if (this.id) this.id.transpile(code, transforms); if (this.init) this.init.transpile(code, transforms); } isLeftDeclaratorOfLoop() { return ( this.parent && this.parent.type === 'VariableDeclaration' && this.parent.parent && (this.parent.parent.type === 'ForInStatement' || this.parent.parent.type === 'ForOfStatement') && this.parent.parent.left && this.parent.parent.left.declarations[0] === this ); } } buble-0.19.8/src/program/types/index.js000066400000000000000000000066321350705536200177660ustar00rootroot00000000000000import ArrayExpression from './ArrayExpression.js'; import ArrowFunctionExpression from './ArrowFunctionExpression.js'; import AssignmentExpression from './AssignmentExpression.js'; import AwaitExpression from './AwaitExpression.js'; import BinaryExpression from './BinaryExpression.js'; import BreakStatement from './BreakStatement.js'; import CallExpression from './CallExpression.js'; import ClassBody from './ClassBody.js'; import ClassDeclaration from './ClassDeclaration.js'; import ClassExpression from './ClassExpression.js'; import ContinueStatement from './ContinueStatement.js'; import ExportDefaultDeclaration from './ExportDefaultDeclaration.js'; import ExportNamedDeclaration from './ExportNamedDeclaration.js'; import ForStatement from './ForStatement.js'; import ForInStatement from './ForInStatement.js'; import ForOfStatement from './ForOfStatement.js'; import FunctionDeclaration from './FunctionDeclaration.js'; import FunctionExpression from './FunctionExpression.js'; import Identifier from './Identifier.js'; import IfStatement from './IfStatement.js'; import Import from './Import.js'; import ImportDeclaration from './ImportDeclaration.js'; import ImportDefaultSpecifier from './ImportDefaultSpecifier.js'; import ImportSpecifier from './ImportSpecifier.js'; import JSXAttribute from './JSXAttribute.js'; import JSXClosingElement from './JSXClosingElement.js'; import JSXClosingFragment from './JSXClosingFragment.js'; import JSXElement from './JSXElement.js'; import JSXExpressionContainer from './JSXExpressionContainer.js'; import JSXFragment from './JSXFragment.js'; import JSXOpeningElement from './JSXOpeningElement.js'; import JSXOpeningFragment from './JSXOpeningFragment.js'; import JSXSpreadAttribute from './JSXSpreadAttribute.js'; import Literal from './Literal.js'; import LoopStatement from './shared/LoopStatement.js'; import MemberExpression from './MemberExpression.js'; import NewExpression from './NewExpression.js'; import ObjectExpression from './ObjectExpression.js'; import Property from './Property.js'; import ReturnStatement from './ReturnStatement.js'; import Super from './Super.js'; import TaggedTemplateExpression from './TaggedTemplateExpression.js'; import TemplateElement from './TemplateElement.js'; import TemplateLiteral from './TemplateLiteral.js'; import ThisExpression from './ThisExpression.js'; import UpdateExpression from './UpdateExpression.js'; import VariableDeclaration from './VariableDeclaration.js'; import VariableDeclarator from './VariableDeclarator.js'; export default { ArrayExpression, ArrowFunctionExpression, AssignmentExpression, AwaitExpression, BinaryExpression, BreakStatement, CallExpression, ClassBody, ClassDeclaration, ClassExpression, ContinueStatement, DoWhileStatement: LoopStatement, ExportNamedDeclaration, ExportDefaultDeclaration, ForStatement, ForInStatement, ForOfStatement, FunctionDeclaration, FunctionExpression, Identifier, IfStatement, Import, ImportDeclaration, ImportDefaultSpecifier, ImportSpecifier, JSXAttribute, JSXClosingElement, JSXClosingFragment, JSXElement, JSXExpressionContainer, JSXFragment, JSXOpeningElement, JSXOpeningFragment, JSXSpreadAttribute, Literal, MemberExpression, NewExpression, ObjectExpression, Property, ReturnStatement, Super, TaggedTemplateExpression, TemplateElement, TemplateLiteral, ThisExpression, UpdateExpression, VariableDeclaration, VariableDeclarator, WhileStatement: LoopStatement }; buble-0.19.8/src/program/types/shared/000077500000000000000000000000001350705536200175605ustar00rootroot00000000000000buble-0.19.8/src/program/types/shared/LoopStatement.js000066400000000000000000000061371350705536200227230ustar00rootroot00000000000000import Node from '../../Node.js'; export default class LoopStatement extends Node { findScope(functionScope) { return functionScope || !this.createdScope ? this.parent.findScope(functionScope) : this.body.scope; } initialise(transforms) { this.body.createScope(); this.createdScope = true; // this is populated as and when reassignments occur this.reassigned = Object.create(null); this.aliases = Object.create(null); this.thisRefs = []; super.initialise(transforms); if (transforms.letConst) { // see if any block-scoped declarations are referenced // inside function expressions const names = Object.keys(this.body.scope.declarations); let i = names.length; while (i--) { const name = names[i]; const declaration = this.body.scope.declarations[name]; let j = declaration.instances.length; while (j--) { const instance = declaration.instances[j]; const nearestFunctionExpression = instance.findNearest(/Function/); if ( nearestFunctionExpression && nearestFunctionExpression.depth > this.depth ) { this.shouldRewriteAsFunction = true; for (const node of this.thisRefs) { node.alias = node.alias || node.findLexicalBoundary().getThisAlias(); } break; } } if (this.shouldRewriteAsFunction) break; } } } transpile(code, transforms) { const needsBlock = this.type != 'ForOfStatement' && (this.body.type !== 'BlockStatement' || (this.body.type === 'BlockStatement' && this.body.synthetic)); if (this.shouldRewriteAsFunction) { const i0 = this.getIndentation(); const i1 = i0 + code.getIndentString(); const argString = this.args ? ` ${this.args.join(', ')} ` : ''; const paramString = this.params ? ` ${this.params.join(', ')} ` : ''; const functionScope = this.findScope(true); const loop = functionScope.createIdentifier('loop'); const before = `var ${loop} = function (${paramString}) ` + (this.body.synthetic ? `{\n${i0}${code.getIndentString()}` : ''); const after = (this.body.synthetic ? `\n${i0}}` : '') + `;\n\n${i0}`; code.prependRight(this.body.start, before); code.appendLeft(this.body.end, after); code.move(this.start, this.body.start, this.body.end); if (this.canBreak || this.canReturn) { const returned = functionScope.createIdentifier('returned'); let insert = `{\n${i1}var ${returned} = ${loop}(${argString});\n`; if (this.canBreak) insert += `\n${i1}if ( ${returned} === 'break' ) break;`; if (this.canReturn) insert += `\n${i1}if ( ${returned} ) return ${returned}.v;`; insert += `\n${i0}}`; code.prependRight(this.body.end, insert); } else { const callExpression = `${loop}(${argString});`; if (this.type === 'DoWhileStatement') { code.overwrite( this.start, this.body.start, `do {\n${i1}${callExpression}\n${i0}}` ); } else { code.prependRight(this.body.end, callExpression); } } } else if (needsBlock) { code.appendLeft(this.body.start, '{ '); code.prependRight(this.body.end, ' }'); } super.transpile(code, transforms); } } buble-0.19.8/src/program/types/shared/ModuleDeclaration.js000066400000000000000000000004651350705536200235160ustar00rootroot00000000000000import Node from '../../Node.js'; import CompileError from '../../../utils/CompileError.js'; export default class ModuleDeclaration extends Node { initialise(transforms) { if (transforms.moduleImport) CompileError.missingTransform('modules', 'moduleImport', this); super.initialise(transforms); } } buble-0.19.8/src/program/wrap.js000066400000000000000000000033171350705536200164610ustar00rootroot00000000000000import types from './types/index.js'; import BlockStatement from './BlockStatement.js'; import Node from './Node.js'; import keys from './keys.js'; const statementsWithBlocks = { IfStatement: 'consequent', ForStatement: 'body', ForInStatement: 'body', ForOfStatement: 'body', WhileStatement: 'body', DoWhileStatement: 'body', ArrowFunctionExpression: 'body' }; export default function wrap(raw, parent) { if (!raw) return; if ('length' in raw) { let i = raw.length; while (i--) wrap(raw[i], parent); return; } // with e.g. shorthand properties, key and value are // the same node. We don't want to wrap an object twice if (raw.__wrapped) return; raw.__wrapped = true; if (!keys[raw.type]) { keys[raw.type] = Object.keys(raw).filter( key => typeof raw[key] === 'object' ); } // special case – body-less if/for/while statements. TODO others? const bodyType = statementsWithBlocks[raw.type]; if (bodyType && raw[bodyType].type !== 'BlockStatement') { const expression = raw[bodyType]; // create a synthetic block statement, otherwise all hell // breaks loose when it comes to block scoping raw[bodyType] = { start: expression.start, end: expression.end, type: 'BlockStatement', body: [expression], synthetic: true }; } raw.parent = parent; raw.program = parent.program || parent; raw.depth = parent.depth + 1; raw.keys = keys[raw.type]; raw.indentation = undefined; for (const key of keys[raw.type]) { wrap(raw[key], raw); } raw.program.magicString.addSourcemapLocation(raw.start); raw.program.magicString.addSourcemapLocation(raw.end); const type = (raw.type === 'BlockStatement' ? BlockStatement : types[raw.type]) || Node; raw.__proto__ = type.prototype; } buble-0.19.8/src/support.js000066400000000000000000000065011350705536200155530ustar00rootroot00000000000000export const matrix = { chrome: { 48: 0b00010010101000110011111, 49: 0b00010011111001111111111, 50: 0b00010111111001111111111, 51: 0b00010111111001111111111, 52: 0b00011111111001111111111, 53: 0b00011111111001111111111, 54: 0b00011111111001111111111, 55: 0b01011111111001111111111, 56: 0b01011111111001111111111, 57: 0b01011111111001111111111, 58: 0b01111111111001111111111, 59: 0b01111111111001111111111, 60: 0b11111111111001111111111, 61: 0b11111111111001111111111, 62: 0b11111111111001111111111, 63: 0b11111111111001111111111, 64: 0b11111111111001111111111, 65: 0b11111111111001111111111, 66: 0b11111111111001111111111, 67: 0b11111111111001111111111, 68: 0b11111111111001111111111, 69: 0b11111111111001111111111, 70: 0b11111111111001111111111, 71: 0b11111111111001111111111 }, firefox: { 43: 0b00010011101000110111011, 44: 0b00010011101000110111011, 45: 0b00010011101000110111111, 46: 0b00010111101000110111111, 47: 0b00010111101000111111111, 48: 0b00010111101000111111111, 49: 0b00010111101000111111111, 50: 0b00010111101000111111111, 51: 0b00010111101001111111111, 52: 0b01111111111001111111111, 53: 0b01111111111001111111111, 54: 0b01111111111001111111111, 55: 0b11111111111001111111111, 56: 0b11111111111001111111111, 57: 0b11111111111001111111111, 58: 0b11111111111001111111111, 59: 0b11111111111001111111111, 60: 0b11111111111001111111111, 61: 0b11111111111001111111111, 62: 0b11111111111001111111111, 63: 0b11111111111001111111111, 64: 0b11111111111001111111111 }, safari: { 8: 0b00010000000000000001001, 9: 0b00010010001000011011101, 10: 0b00110111111001111111111, '10.1': 0b01111111111001111111111, 11: 0b01111111111001111111111, '11.1': 0b11111111111001111111111, 12: 0b11111111111001111111111 }, ie: { 8: 0b00000000000000000000000, 9: 0b00010000000000000000001, 10: 0b00010000000000000000001, 11: 0b00010000000000000000001 // no let/const in for loops }, edge: { 12: 0b00010010101000010011011, 13: 0b00010111101000110011111, 14: 0b00111111101001111111111, 15: 0b01111111101001111111111, 16: 0b01111111101001111111111, 17: 0b01111111101001111111111, 18: 0b01111111101001111111111, 19: 0b01111111101001111111111 }, node: { '0.10': 0b00010000000000000000001, '0.12': 0b00010000000000010000001, 4: 0b00010010001000110011111, 5: 0b00010010001000110011111, 6: 0b00010111111001111111111, 8: 0b01111111111001111111111, '8.3': 0b11111111111001111111111, '8.7': 0b11111111111001111111111, '8.10': 0b11111111111001111111111 } }; export const features = [ 'getterSetter', 'arrow', 'classes', 'computedProperty', 'conciseMethodProperty', 'defaultParameter', 'destructuring', 'forOf', 'generator', 'letConst', 'moduleExport', 'moduleImport', 'numericLiteral', 'parameterDestructuring', 'spreadRest', 'stickyRegExp', 'templateString', 'unicodeRegExp', // ES2016 'exponentiation', // additional transforms, not from // https://featuretests.io 'reservedProperties', 'trailingFunctionCommas', 'asyncAwait', 'objectRestSpread' ]; buble-0.19.8/src/utils/000077500000000000000000000000001350705536200146375ustar00rootroot00000000000000buble-0.19.8/src/utils/CompileError.js000066400000000000000000000021061350705536200175760ustar00rootroot00000000000000import locate from './locate.js'; import getSnippet from './getSnippet.js'; export default class CompileError extends Error { constructor(message, node) { super(message); this.name = 'CompileError'; if (!node) { return; } const source = node.program.magicString.original; const loc = locate(source, node.start); this.message = message + ` (${loc.line}:${loc.column})`; this.stack = new Error().stack.replace( new RegExp(`.+new ${this.name}.+\\n`, 'm'), '' ); this.loc = loc; this.snippet = getSnippet(source, loc, node.end - node.start); } toString() { return `${this.name}: ${this.message}\n${this.snippet}`; } static missingTransform(feature, transformKey, node, dangerousKey = null) { const maybeDangerous = dangerousKey ? `, or \`transforms: { ${dangerousKey}: true }\` if you know what you're doing` : ''; throw new CompileError(`Transforming ${feature} is not ${dangerousKey ? "fully supported" : "implemented"}. Use \`transforms: { ${transformKey}: false }\` to skip transformation and disable this error${maybeDangerous}.`, node); } } buble-0.19.8/src/utils/array.js000066400000000000000000000003211350705536200163070ustar00rootroot00000000000000export function findIndex(array, fn) { for (let i = 0; i < array.length; i += 1) { if (fn(array[i], i)) return i; } return -1; } export function find(array, fn) { return array[findIndex(array, fn)]; } buble-0.19.8/src/utils/checkConst.js000066400000000000000000000004461350705536200172650ustar00rootroot00000000000000import CompileError from './CompileError.js'; export default function checkConst(identifier, scope) { const declaration = scope.findDeclaration(identifier.name); if (declaration && declaration.kind === 'const') { throw new CompileError(`${identifier.name} is read-only`, identifier); } } buble-0.19.8/src/utils/deindent.js000066400000000000000000000016061350705536200167720ustar00rootroot00000000000000// TODO this function is slightly flawed – it works on the original string, // not its current edited state. // That's not a problem for the way that it's currently used, but it could // be in future... export default function deindent(node, code) { const start = node.start; const end = node.end; const indentStr = code.getIndentString(); const indentStrLen = indentStr.length; const indentStart = start - indentStrLen; if ( !node.program.indentExclusions[indentStart] && code.original.slice(indentStart, start) === indentStr ) { code.remove(indentStart, start); } const pattern = new RegExp(indentStr + '\\S', 'g'); const slice = code.original.slice(start, end); let match; while ((match = pattern.exec(slice))) { const removeStart = start + match.index; if (!node.program.indentExclusions[removeStart]) { code.remove(removeStart, removeStart + indentStrLen); } } } buble-0.19.8/src/utils/destructure.js000066400000000000000000000177411350705536200175600ustar00rootroot00000000000000import CompileError from '../utils/CompileError.js'; import { findIndex } from './array.js'; const handlers = { Identifier: destructureIdentifier, AssignmentPattern: destructureAssignmentPattern, ArrayPattern: destructureArrayPattern, ObjectPattern: destructureObjectPattern }; export default function destructure( code, createIdentifier, resolveName, node, ref, inline, statementGenerators ) { handlers[node.type](code, createIdentifier, resolveName, node, ref, inline, statementGenerators); } function destructureIdentifier( code, createIdentifier, resolveName, node, ref, inline, statementGenerators ) { statementGenerators.push((start, prefix, suffix) => { code.overwrite(node.start, node.end, (inline ? prefix : `${prefix}var `) + resolveName(node) + ` = ${ref}${suffix}`); code.move(node.start, node.end, start); }); } function destructureMemberExpression( code, createIdentifier, resolveName, node, ref, inline, statementGenerators ) { statementGenerators.push((start, prefix, suffix) => { code.prependRight(node.start, inline ? prefix : `${prefix}var `); code.appendLeft(node.end, ` = ${ref}${suffix}`); code.move(node.start, node.end, start); }); } function destructureAssignmentPattern( code, createIdentifier, resolveName, node, ref, inline, statementGenerators ) { const isIdentifier = node.left.type === 'Identifier'; const name = isIdentifier ? node.left.name : ref; if (!inline) { statementGenerators.push((start, prefix, suffix) => { code.prependRight( node.left.end, `${prefix}if ( ${name} === void 0 ) ${name}` ); code.move(node.left.end, node.right.end, start); code.appendLeft(node.right.end, suffix); }); } if (!isIdentifier) { destructure(code, createIdentifier, resolveName, node.left, ref, inline, statementGenerators); } } function destructureArrayPattern( code, createIdentifier, resolveName, node, ref, inline, statementGenerators ) { let c = node.start; node.elements.forEach((element, i) => { if (!element) return; if (element.type === 'RestElement') { handleProperty( code, createIdentifier, resolveName, c, element.argument, `${ref}.slice(${i})`, inline, statementGenerators ); } else { handleProperty( code, createIdentifier, resolveName, c, element, `${ref}[${i}]`, inline, statementGenerators ); } c = element.end; }); code.remove(c, node.end); } function destructureObjectPattern( code, createIdentifier, resolveName, node, ref, inline, statementGenerators ) { let c = node.start; const nonRestKeys = []; node.properties.forEach(prop => { let value; let content; if (prop.type === 'Property') { content = prop.value; if (!prop.computed && prop.key.type === 'Identifier') { value = `${ref}.${prop.key.name}`; nonRestKeys.push(`"${prop.key.name}"`); } else if (!prop.computed && prop.key.type === 'Literal') { value = `${ref}[${prop.key.raw}]`; nonRestKeys.push(JSON.stringify(String(prop.key.value))); } else { const expr = code.slice(prop.key.start, prop.key.end); value = `${ref}[${expr}]`; nonRestKeys.push(`String(${expr})`); } } else if (prop.type === 'RestElement') { content = prop.argument; value = createIdentifier('rest'); statementGenerators.push((start, prefix, suffix) => { const helper = prop.program.getObjectWithoutPropertiesHelper(code); code.overwrite( prop.start, (c = prop.argument.start), (inline ? prefix : `${prefix}var `) + `${value} = ${helper}( ${ref}, [${nonRestKeys.join(', ')}] )${suffix}` ); code.move(prop.start, c, start); }); } else { throw new CompileError( this, `Unexpected node of type ${prop.type} in object pattern` ); } handleProperty(code, createIdentifier, resolveName, c, content, value, inline, statementGenerators); c = prop.end; }); code.remove(c, node.end); } function handleProperty( code, createIdentifier, resolveName, c, node, value, inline, statementGenerators ) { switch (node.type) { case 'Identifier': { code.remove(c, node.start); destructureIdentifier( code, createIdentifier, resolveName, node, value, inline, statementGenerators ); break; } case 'MemberExpression': code.remove(c, node.start); destructureMemberExpression( code, createIdentifier, resolveName, node, value, true, statementGenerators ); break; case 'AssignmentPattern': { let name; const isIdentifier = node.left.type === 'Identifier'; if (isIdentifier) { name = resolveName(node.left); } else { name = createIdentifier(value); } statementGenerators.push((start, prefix, suffix) => { if (inline) { code.prependRight( node.right.start, `${name} = ${value}, ${name} = ${name} === void 0 ? ` ); code.appendLeft(node.right.end, ` : ${name}${suffix}`); } else { code.prependRight( node.right.start, `${prefix}var ${name} = ${value}; if ( ${name} === void 0 ) ${name} = ` ); code.appendLeft(node.right.end, suffix); } code.move(node.right.start, node.right.end, start); }); if (isIdentifier) { code.remove(c, node.right.start); } else { code.remove(c, node.left.start); code.remove(node.left.end, node.right.start); handleProperty( code, createIdentifier, resolveName, c, node.left, name, inline, statementGenerators ); } break; } case 'ObjectPattern': { code.remove(c, (c = node.start)); let ref = value; if (node.properties.length > 1) { ref = createIdentifier(value); statementGenerators.push((start, prefix, suffix) => { // this feels a tiny bit hacky, but we can't do a // straightforward appendLeft and keep correct order... code.prependRight(node.start, (inline ? '' : `${prefix}var `) + `${ref} = `); code.overwrite(node.start, (c = node.start + 1), value); code.appendLeft(c, suffix); code.overwrite( node.start, (c = node.start + 1), (inline ? '' : `${prefix}var `) + `${ref} = ${value}${suffix}` ); code.move(node.start, c, start); }); } destructureObjectPattern( code, createIdentifier, resolveName, node, ref, inline, statementGenerators ); break; } case 'ArrayPattern': { code.remove(c, (c = node.start)); if (node.elements.filter(Boolean).length > 1) { const ref = createIdentifier(value); statementGenerators.push((start, prefix, suffix) => { code.prependRight(node.start, (inline ? '' : `${prefix}var `) + `${ref} = `); code.overwrite(node.start, (c = node.start + 1), value, { contentOnly: true }); code.appendLeft(c, suffix); code.move(node.start, c, start); }); node.elements.forEach((element, i) => { if (!element) return; if (element.type === 'RestElement') { handleProperty( code, createIdentifier, resolveName, c, element.argument, `${ref}.slice(${i})`, inline, statementGenerators ); } else { handleProperty( code, createIdentifier, resolveName, c, element, `${ref}[${i}]`, inline, statementGenerators ); } c = element.end; }); } else { const index = findIndex(node.elements, Boolean); const element = node.elements[index]; if (element.type === 'RestElement') { handleProperty( code, createIdentifier, resolveName, c, element.argument, `${value}.slice(${index})`, inline, statementGenerators ); } else { handleProperty( code, createIdentifier, resolveName, c, element, `${value}[${index}]`, inline, statementGenerators ); } c = element.end; } code.remove(c, node.end); break; } default: { throw new Error(`Unexpected node type in destructuring (${node.type})`); } } } buble-0.19.8/src/utils/getSnippet.js000066400000000000000000000014051350705536200173170ustar00rootroot00000000000000function pad(num, len) { const result = String(num); return result + repeat(' ', len - result.length); } function repeat(str, times) { let result = ''; while (times--) result += str; return result; } export default function getSnippet(source, loc, length = 1) { const first = Math.max(loc.line - 5, 0); const last = loc.line; const numDigits = String(last).length; const lines = source.split('\n').slice(first, last); const lastLine = lines[lines.length - 1]; const offset = lastLine.slice(0, loc.column).replace(/\t/g, ' ').length; let snippet = lines .map((line, i) => `${pad(i + first + 1, numDigits)} : ${line.replace(/\t/g, ' ')}`) .join('\n'); snippet += '\n' + repeat(' ', numDigits + 3 + offset) + repeat('^', length); return snippet; } buble-0.19.8/src/utils/isReference.js000066400000000000000000000024111350705536200174250ustar00rootroot00000000000000export default function isReference(node, parent) { if (node.type === 'MemberExpression') { return !node.computed && isReference(node.object, node); } if (node.type === 'Identifier') { // the only time we could have an identifier node without a parent is // if it's the entire body of a function without a block statement – // i.e. an arrow function expression like `a => a` if (!parent) return true; if (/(Function|Class)Expression/.test(parent.type)) return false; if (parent.type === 'VariableDeclarator') return node === parent.init; // TODO is this right? if ( parent.type === 'MemberExpression' || parent.type === 'MethodDefinition' ) { return parent.computed || node === parent.object; } if (parent.type === 'ArrayPattern') return false; // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }` if (parent.type === 'Property') { if (parent.parent.type === 'ObjectPattern') return false; return parent.computed || node === parent.value; } // disregard the `bar` in `class Foo { bar () {...} }` if (parent.type === 'MethodDefinition') return false; // disregard the `bar` in `export { foo as bar }` if (parent.type === 'ExportSpecifier' && node !== parent.local) return false; return true; } } buble-0.19.8/src/utils/locate.js000066400000000000000000000007001350705536200164410ustar00rootroot00000000000000export default function locate(source, index) { const lines = source.split('\n'); const len = lines.length; let lineStart = 0; let i; for (i = 0; i < len; i += 1) { const line = lines[i]; const lineEnd = lineStart + line.length + 1; // +1 for newline if (lineEnd > index) { return { line: i + 1, column: index - lineStart, char: i }; } lineStart = lineEnd; } throw new Error('Could not determine location of character'); } buble-0.19.8/src/utils/patterns.js000066400000000000000000000001011350705536200170250ustar00rootroot00000000000000export const loopStatement = /(?:For(?:In|Of)?|While)Statement/; buble-0.19.8/src/utils/removeTrailingComma.js000066400000000000000000000005501350705536200211410ustar00rootroot00000000000000export default function removeTrailingComma(code, c) { while (code.original[c] !== ')') { if (code.original[c] === ',') { code.remove(c, c + 1); return; } if (code.original[c] === '/') { if (code.original[c + 1] === '/') { c = code.original.indexOf('\n', c); } else { c = code.original.indexOf('*/', c) + 1; } } c += 1; } } buble-0.19.8/src/utils/reserved.js000066400000000000000000000006601350705536200170160ustar00rootroot00000000000000const reserved = Object.create(null); 'do if in for let new try var case else enum eval null this true void with await break catch class const false super throw while yield delete export import public return static switch typeof default extends finally package private continue debugger function arguments interface protected implements instanceof' .split(' ') .forEach(word => (reserved[word] = true)); export default reserved; buble-0.19.8/src/utils/spread.js000066400000000000000000000113671350705536200164630ustar00rootroot00000000000000import CompileError from './CompileError.js'; export function isArguments(node) { return node.type === 'Identifier' && node.name === 'arguments'; } export function inlineSpreads( code, node, elements ) { let i = elements.length; while (i--) { const element = elements[i]; if (!element || element.type !== 'SpreadElement') { continue; } const argument = element.argument; if (argument.type !== 'ArrayExpression') { continue; } const subelements = argument.elements; if (subelements.some(subelement => subelement === null)) { // Not even going to try inlining spread arrays with holes. // It's a lot of work (got to be VERY careful in comma counting for // ArrayExpression, and turn blanks into undefined for // CallExpression and NewExpression), and probably literally no one // would ever benefit from it. continue; } // We can inline it: drop the `...[` and `]` and sort out any commas. const isLast = i === elements.length - 1; if (subelements.length === 0) { code.remove( isLast && i !== 0 ? elements[i - 1].end // Take the previous comma too : element.start, isLast ? node.end - 1 // Must remove trailing comma; element.end wouldn’t : elements[i + 1].start); } else { // Strip the `...[` and the `]` with a possible trailing comma before it, // leaving just the possible trailing comma after it. code.remove(element.start, subelements[0].start); code.remove( // Strip a possible trailing comma after the last element subelements[subelements.length - 1].end, // And also a possible trailing comma after the spread isLast ? node.end - 1 : element.end ); } elements.splice(i, 1, ...subelements); i += subelements.length; } } // Returns false if it’s safe to simply append a method call to the node, // e.g. `a` → `a.concat()`. // // Returns true if it may not be and so parentheses should be employed, // e.g. `a ? b : c` → `a ? b : c.concat()` would be wrong. // // This test may be overcautious; if desired it can be refined over time. export function needsParentheses(node) { switch (node.type) { // Currently whitelisted are all relevant ES5 node types ('Literal' and // 'ObjectExpression' are skipped as irrelevant for array/call spread.) case 'ArrayExpression': case 'CallExpression': case 'Identifier': case 'ParenthesizedExpression': case 'ThisExpression': return false; default: return true; } } export default function spread( code, elements, start, argumentsArrayAlias, isNew ) { let i = elements.length; let firstSpreadIndex = -1; while (i--) { const element = elements[i]; if (element && element.type === 'SpreadElement') { if (isArguments(element.argument)) { code.overwrite( element.argument.start, element.argument.end, argumentsArrayAlias ); } firstSpreadIndex = i; } } if (firstSpreadIndex === -1) return false; // false indicates no spread elements if (isNew) { for (i = 0; i < elements.length; i += 1) { const element = elements[i]; if (element.type === 'SpreadElement') { code.remove(element.start, element.argument.start); } else { code.prependRight(element.start, '['); code.prependRight(element.end, ']'); } } return true; // true indicates some spread elements } let element = elements[firstSpreadIndex]; const previousElement = elements[firstSpreadIndex - 1]; if (!previousElement) { // We may need to parenthesize it to handle ternaries like [...a ? b : c]. let addClosingParen; if (start !== element.start) { if ((addClosingParen = needsParentheses(element.argument))) { code.overwrite(start, element.start, '( '); } else { code.remove(start, element.start); } } else if (element.parent.type === 'CallExpression') { // CallExpression inserts `( ` itself, we add the ). // (Yeah, CallExpression did the needsParentheses call already, // but we don’t have its result handy, so do it again. It’s cheap.) addClosingParen = needsParentheses(element.argument); } else { // Should be unreachable, but doing this is more robust. throw new CompileError( 'Unsupported spread construct, please raise an issue at https://github.com/bublejs/buble/issues', element ); } code.overwrite(element.end, elements[1].start, addClosingParen ? ' ).concat( ' : '.concat( '); } else { code.overwrite(previousElement.end, element.start, ' ].concat( '); } for (i = firstSpreadIndex; i < elements.length; i += 1) { element = elements[i]; if (element) { if (element.type === 'SpreadElement') { code.remove(element.start, element.argument.start); } else { code.appendLeft(element.start, '['); code.appendLeft(element.end, ']'); } } } return true; // true indicates some spread elements } buble-0.19.8/test/000077500000000000000000000000001350705536200136675ustar00rootroot00000000000000buble-0.19.8/test/.eslintrc.json000066400000000000000000000001461350705536200164640ustar00rootroot00000000000000{ "env": { "mocha": true }, "rules": { "no-console": "off", "no-var": "off" } } buble-0.19.8/test/bundlers/000077500000000000000000000000001350705536200155055ustar00rootroot00000000000000buble-0.19.8/test/bundlers/index.js000066400000000000000000000001211350705536200171440ustar00rootroot00000000000000import { transform } from "../../"; console.log(transform("const x = 4").code); buble-0.19.8/test/bundlers/rollup.config.js000066400000000000000000000003301350705536200206200ustar00rootroot00000000000000import resolve from 'rollup-plugin-node-resolve'; import commonjs from 'rollup-plugin-commonjs'; export default { input: __dirname + '/index.js', output: {format: 'es'}, plugins: [ commonjs(), resolve() ], }; buble-0.19.8/test/bundlers/webpack.js000066400000000000000000000003421350705536200174560ustar00rootroot00000000000000const assert = require('assert'); const webpack = require('webpack'); webpack({ entry: "./index.js", mode: "none" }, (err, stats) => { assert(!stats.hasErrors()) assert.deepStrictEqual(stats.compilation.warnings, []) }); buble-0.19.8/test/cli/000077500000000000000000000000001350705536200144365ustar00rootroot00000000000000buble-0.19.8/test/cli/basic/000077500000000000000000000000001350705536200155175ustar00rootroot00000000000000buble-0.19.8/test/cli/basic/command.sh000077500000000000000000000000431350705536200174710ustar00rootroot00000000000000buble input.js -o actual/output.js buble-0.19.8/test/cli/basic/expected/000077500000000000000000000000001350705536200173205ustar00rootroot00000000000000buble-0.19.8/test/cli/basic/expected/output.js000066400000000000000000000000511350705536200212120ustar00rootroot00000000000000var answer = function () { return 42; }; buble-0.19.8/test/cli/basic/input.js000066400000000000000000000000311350705536200172060ustar00rootroot00000000000000const answer = () => 42; buble-0.19.8/test/cli/compiles-directory/000077500000000000000000000000001350705536200202535ustar00rootroot00000000000000buble-0.19.8/test/cli/compiles-directory/command.sh000077500000000000000000000000271350705536200222270ustar00rootroot00000000000000buble src -o actual -m buble-0.19.8/test/cli/compiles-directory/expected/000077500000000000000000000000001350705536200220545ustar00rootroot00000000000000buble-0.19.8/test/cli/compiles-directory/expected/bar.js000066400000000000000000000000651350705536200231570ustar00rootroot00000000000000console.log( 'bar' ); //# sourceMappingURL=bar.js.mapbuble-0.19.8/test/cli/compiles-directory/expected/bar.js.map000066400000000000000000000002411350705536200237270ustar00rootroot00000000000000{"version":3,"file":"bar.js","sources":["../src/bar.jsm"],"sourcesContent":["console.log( 'bar' );"],"names":[],"mappings":"AAAA,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE"} buble-0.19.8/test/cli/compiles-directory/expected/baz.js000066400000000000000000000000651350705536200231670ustar00rootroot00000000000000console.log( 'baz' ); //# sourceMappingURL=baz.js.mapbuble-0.19.8/test/cli/compiles-directory/expected/baz.js.map000066400000000000000000000002401350705536200237360ustar00rootroot00000000000000{"version":3,"file":"baz.js","sources":["../src/baz.es6"],"sourcesContent":["console.log( 'baz' );"],"names":[],"mappings":"AAAA,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE"}buble-0.19.8/test/cli/compiles-directory/expected/foo.js000066400000000000000000000000641350705536200231750ustar00rootroot00000000000000console.log('foo'); //# sourceMappingURL=foo.js.mapbuble-0.19.8/test/cli/compiles-directory/expected/foo.js.map000066400000000000000000000002451350705536200237520ustar00rootroot00000000000000{"version":3,"file":"foo.js","sources":["../src/foo.js"],"sourcesContent":["console.log('foo');\n"],"names":[],"mappings":"AAAA,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;"}buble-0.19.8/test/cli/compiles-directory/src/000077500000000000000000000000001350705536200210425ustar00rootroot00000000000000buble-0.19.8/test/cli/compiles-directory/src/bar.jsm000066400000000000000000000000251350705536200223160ustar00rootroot00000000000000console.log( 'bar' );buble-0.19.8/test/cli/compiles-directory/src/baz.es6000066400000000000000000000000251350705536200222320ustar00rootroot00000000000000console.log( 'baz' );buble-0.19.8/test/cli/compiles-directory/src/foo.js000066400000000000000000000000241350705536200221570ustar00rootroot00000000000000console.log('foo'); buble-0.19.8/test/cli/compiles-directory/src/nope.txt000066400000000000000000000000051350705536200225370ustar00rootroot00000000000000nope buble-0.19.8/test/cli/creates-inline-sourcemap/000077500000000000000000000000001350705536200213345ustar00rootroot00000000000000buble-0.19.8/test/cli/creates-inline-sourcemap/command.sh000077500000000000000000000000551350705536200233110ustar00rootroot00000000000000buble input.js -o actual/output.js -m inline buble-0.19.8/test/cli/creates-inline-sourcemap/expected/000077500000000000000000000000001350705536200231355ustar00rootroot00000000000000buble-0.19.8/test/cli/creates-inline-sourcemap/expected/output.js000066400000000000000000000005421350705536200250340ustar00rootroot00000000000000var answer = function () { return 42; }; //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3V0cHV0LmpzIiwic291cmNlcyI6WyIuLi9pbnB1dC5qcyJdLCJzb3VyY2VzQ29udGVudCI6WyJjb25zdCBhbnN3ZXIgPSAoKSA9PiA0MjtcbiJdLCJuYW1lcyI6WyJjb25zdCJdLCJtYXBwaW5ncyI6IkFBQUFBLEdBQUssQ0FBQyxNQUFNLFlBQUcsR0FBRyxTQUFHLEtBQUUsQ0FBQzsifQ==buble-0.19.8/test/cli/creates-inline-sourcemap/input.js000066400000000000000000000000311350705536200230230ustar00rootroot00000000000000const answer = () => 42; buble-0.19.8/test/cli/creates-sourcemap/000077500000000000000000000000001350705536200200605ustar00rootroot00000000000000buble-0.19.8/test/cli/creates-sourcemap/command.sh000077500000000000000000000000461350705536200220350ustar00rootroot00000000000000buble input.js -o actual/output.js -m buble-0.19.8/test/cli/creates-sourcemap/expected/000077500000000000000000000000001350705536200216615ustar00rootroot00000000000000buble-0.19.8/test/cli/creates-sourcemap/expected/output.js000066400000000000000000000001141350705536200235530ustar00rootroot00000000000000var answer = function () { return 42; }; //# sourceMappingURL=output.js.mapbuble-0.19.8/test/cli/creates-sourcemap/expected/output.js.map000066400000000000000000000002701350705536200243320ustar00rootroot00000000000000{"version":3,"file":"output.js","sources":["../input.js"],"sourcesContent":["const answer = () => 42;\n"],"names":["const"],"mappings":"AAAAA,GAAK,CAAC,MAAM,YAAG,GAAG,SAAG,KAAE,CAAC;"}buble-0.19.8/test/cli/creates-sourcemap/input.js000066400000000000000000000000311350705536200215470ustar00rootroot00000000000000const answer = () => 42; buble-0.19.8/test/cli/supports-jsx-pragma-comment/000077500000000000000000000000001350705536200220445ustar00rootroot00000000000000buble-0.19.8/test/cli/supports-jsx-pragma-comment/command.sh000066400000000000000000000001001350705536200240050ustar00rootroot00000000000000buble input.js -o actual/output.js --jsx NotReact.createElement buble-0.19.8/test/cli/supports-jsx-pragma-comment/expected/000077500000000000000000000000001350705536200236455ustar00rootroot00000000000000buble-0.19.8/test/cli/supports-jsx-pragma-comment/expected/output.js000066400000000000000000000001101350705536200255330ustar00rootroot00000000000000/* @jsx customPragma */ var div = customPragma( 'div', null, "Hello" ); buble-0.19.8/test/cli/supports-jsx-pragma-comment/input.js000066400000000000000000000000641350705536200235410ustar00rootroot00000000000000/* @jsx customPragma */ var div =
Hello
; buble-0.19.8/test/cli/supports-jsx-pragma/000077500000000000000000000000001350705536200204045ustar00rootroot00000000000000buble-0.19.8/test/cli/supports-jsx-pragma/command.sh000066400000000000000000000001001350705536200223450ustar00rootroot00000000000000buble input.js -o actual/output.js --jsx NotReact.createElement buble-0.19.8/test/cli/supports-jsx-pragma/expected/000077500000000000000000000000001350705536200222055ustar00rootroot00000000000000buble-0.19.8/test/cli/supports-jsx-pragma/expected/output.js000066400000000000000000000000761350705536200241060ustar00rootroot00000000000000var img = NotReact.createElement( 'img', { src: "foo.gif" }); buble-0.19.8/test/cli/supports-jsx-pragma/input.js000066400000000000000000000000411350705536200220740ustar00rootroot00000000000000var img = ; buble-0.19.8/test/cli/supports-jsx/000077500000000000000000000000001350705536200171375ustar00rootroot00000000000000buble-0.19.8/test/cli/supports-jsx/command.sh000066400000000000000000000000441350705536200211070ustar00rootroot00000000000000buble input.jsx -o actual/output.js buble-0.19.8/test/cli/supports-jsx/expected/000077500000000000000000000000001350705536200207405ustar00rootroot00000000000000buble-0.19.8/test/cli/supports-jsx/expected/output.js000066400000000000000000000000731350705536200226360ustar00rootroot00000000000000var img = React.createElement( 'img', { src: 'foo.gif' }); buble-0.19.8/test/cli/supports-jsx/input.jsx000066400000000000000000000000401350705536200210160ustar00rootroot00000000000000var img = ; buble-0.19.8/test/cli/uses-overrides/000077500000000000000000000000001350705536200174155ustar00rootroot00000000000000buble-0.19.8/test/cli/uses-overrides/command.sh000077500000000000000000000000571350705536200213740ustar00rootroot00000000000000buble input.js -o actual/output.js -n letConst buble-0.19.8/test/cli/uses-overrides/expected/000077500000000000000000000000001350705536200212165ustar00rootroot00000000000000buble-0.19.8/test/cli/uses-overrides/expected/output.js000066400000000000000000000000531350705536200231120ustar00rootroot00000000000000const answer = function () { return 42; }; buble-0.19.8/test/cli/uses-overrides/input.js000066400000000000000000000000311350705536200211040ustar00rootroot00000000000000const answer = () => 42; buble-0.19.8/test/cli/uses-targets/000077500000000000000000000000001350705536200170645ustar00rootroot00000000000000buble-0.19.8/test/cli/uses-targets/command.sh000077500000000000000000000000611350705536200210360ustar00rootroot00000000000000buble input.js -o actual/output.js -t firefox:43 buble-0.19.8/test/cli/uses-targets/expected/000077500000000000000000000000001350705536200206655ustar00rootroot00000000000000buble-0.19.8/test/cli/uses-targets/expected/output.js000066400000000000000000000000271350705536200225620ustar00rootroot00000000000000var answer = () => 42; buble-0.19.8/test/cli/uses-targets/input.js000066400000000000000000000000311350705536200205530ustar00rootroot00000000000000const answer = () => 42; buble-0.19.8/test/cli/writes-to-stdout/000077500000000000000000000000001350705536200177135ustar00rootroot00000000000000buble-0.19.8/test/cli/writes-to-stdout/command.sh000077500000000000000000000000421350705536200216640ustar00rootroot00000000000000buble input.js > actual/output.js buble-0.19.8/test/cli/writes-to-stdout/expected/000077500000000000000000000000001350705536200215145ustar00rootroot00000000000000buble-0.19.8/test/cli/writes-to-stdout/expected/output.js000066400000000000000000000000521350705536200234070ustar00rootroot00000000000000var answer = function () { return 42; }; buble-0.19.8/test/cli/writes-to-stdout/input.js000066400000000000000000000000311350705536200214020ustar00rootroot00000000000000const answer = () => 42; buble-0.19.8/test/samples/000077500000000000000000000000001350705536200153335ustar00rootroot00000000000000buble-0.19.8/test/samples/arrow-functions.js000066400000000000000000000104511350705536200210320ustar00rootroot00000000000000module.exports = [ { description: 'transpiles an arrow function', input: `var answer = () => 42`, output: `var answer = function () { return 42; }` }, { description: 'transpiles an arrow function with a naked parameter', input: `var double = x => x * 2`, output: `var double = function (x) { return x * 2; }` }, { description: 'transpiles an arrow function with single wrapped parameter', input: `var double = (x) => x * 2`, output: `var double = function (x) { return x * 2; }` }, { description: 'transpiles an arrow function with parenthesised parameters', input: `var add = ( a, b ) => a + b`, output: `var add = function ( a, b ) { return a + b; }` }, { description: 'transpiles an arrow function with a body', input: ` var add = ( a, b ) => { return a + b; };`, output: ` var add = function ( a, b ) { return a + b; };` }, { description: 'replaces `this` inside an arrow function', input: ` this.foo = 'bar'; var lexicallyScoped = () => this.foo;`, output: ` var this$1 = this; this.foo = 'bar'; var lexicallyScoped = function () { return this$1.foo; };` }, { description: 'replaces `arguments` inside an arrow function', input: ` function firstArgument () { return () => arguments[0]; } equal( firstArgument( 1, 2, 3 )(), 1 )`, output: ` function firstArgument () { var arguments$1 = arguments; return function () { return arguments$1[0]; }; } equal( firstArgument( 1, 2, 3 )(), 1 )` }, { description: 'only adds one `this` or `arguments` per context', input: ` function multiply () { return () => { return () => this * arguments[0]; }; } equal( multiply.call( 2, 3 )()(), 6 )`, output: ` function multiply () { var arguments$1 = arguments; var this$1 = this; return function () { return function () { return this$1 * arguments$1[0]; }; }; } equal( multiply.call( 2, 3 )()(), 6 )` }, { description: 'transpiles a body-less arrow function with rest params', input: ` const sum = ( ...nums ) => nums.reduce( ( t, n ) => t + n, 0 );`, output: ` var sum = function () { var nums = [], len = arguments.length; while ( len-- ) nums[ len ] = arguments[ len ]; return nums.reduce( function ( t, n ) { return t + n; }, 0 ); };` }, { description: 'handles combination of destructuring and template strings', input: ` var shoutHello = ({ name }) => \`\${name}! Hello \${name}!\`.toUpperCase();`, output: ` var shoutHello = function (ref) { var name = ref.name; return (name + "! Hello " + name + "!").toUpperCase(); };` }, { description: 'can be disabled with `transforms.arrow: false`', options: { transforms: { arrow: false } }, input: ` var add = ( a, b ) => { console.log( 'this, arguments', this, arguments ) a = b; }`, output: ` var add = ( a, b ) => { console.log( 'this, arguments', this, arguments ) a = b; }` }, { description: 'inserts statements after use strict pragma (#72)', input: ` 'use strict'; setTimeout( () => console.log( this ) ); function foo () { 'use strict'; setTimeout( () => console.log( this ) ); }`, output: ` 'use strict'; var this$1 = this; setTimeout( function () { return console.log( this$1 ); } ); function foo () { 'use strict'; var this$1 = this; setTimeout( function () { return console.log( this$1 ); } ); }` }, { description: 'handles standalone arrow function expression statement', input: ` () => console.log( 'not printed' );`, output: ` !function() { return console.log( 'not printed' ); };` }, { description: 'handles standalone arrow function expression statement within a function', input: ` function no_op () { () => console.log( 'not printed' ); }`, output: ` function no_op () { !function() { return console.log( 'not printed' ); }; }` }, { description: 'are transformed even if disabled if they have a transpiled spread parameter', options: { transforms: { arrow: false, spreadRest: true } }, input: ` (...args) => console.log( args );`, output: ` !function() { var args = [], len = arguments.length; while ( len-- ) args[ len ] = arguments[ len ]; return console.log( args ); };` } ]; buble-0.19.8/test/samples/async.js000066400000000000000000000105011350705536200170030ustar00rootroot00000000000000module.exports = [ { description: 'supports async as property name', input: ` ({async, foo})`, output: ` ({async: async, foo: foo})` }, { description: 'passes through async function declarations if transform is disabled', options: { transforms: { asyncAwait: false } }, input: `async function A() {}`, output: `async function A() {}` }, { description: 'errors on async function declarations if transform is enabled', input: `async function A() {}`, error: /Transforming async functions is not implemented/ }, { description: 'passes through async arrow functions if transform is disabled', options: { transforms: { asyncAwait: false } }, input: `(async () => {})`, output: `(async function () {})` }, { description: 'errors on async arrow functions if transform is enabled', input: `(async () => {})`, error: /Transforming async arrow functions is not implemented/ }, { description: 'passes through async function expressions if transform is disabled', options: { transforms: { asyncAwait: false } }, input: `const A = async function () {}`, output: `var A = async function () {}` }, { description: 'errors on async function expressions if transform is enabled', input: `const A = async function () {}`, error: /Transforming async functions is not implemented/ }, { description: 'passes through async short-hand methods if transform is disabled', options: { transforms: { asyncAwait: false } }, input: `({ async x() {} })`, output: `({ x: async function x() {} })` }, { description: 'errors on async short-hand methods if transform is enabled', input: `({ async x() {} })`, error: /Transforming async functions is not implemented/ }, { description: 'passes through async class methods if transform is disabled', options: { transforms: { asyncAwait: false } }, input: ` (class { async x() {} })`, output: ` (/*@__PURE__*/(function () { function anonymous () {} anonymous.prototype.x = async function x () {}; return anonymous; }()))` }, { description: 'errors on async class methods if transform is enabled', input: `(class { async x() {} })`, error: /Transforming async functions is not implemented/ }, { description: 'passes through async function properties if transform is disabled', options: { transforms: { asyncAwait: false } }, input: `({ x: async function() {} })`, output: `({ x: async function() {} })` }, { description: 'errors on async function properties if transform is enabled', input: `({ x: async function() {} })`, error: /Transforming async functions is not implemented/ }, { description: 'passes through async arrow function properties if transform is disabled', options: { transforms: { asyncAwait: false } }, input: `({ x: async () => {} })`, output: `({ x: async function () {} })` }, { description: 'errors on async arrow function properties if transform is enabled', input: `({ x: async () => {} })`, error: /Transforming async arrow functions is not implemented/ }, { description: 'passes through async arrow function with naked parameter if transform is disabled', options: { transforms: { asyncAwait: false } }, input: `async a => {}`, output: `!async function(a) {}` }, { description: 'errors on async arrow function with naked parameter if transform is enabled', input: `async a => {}`, error: /Transforming async arrow functions is not implemented/ }, { description: 'passes through top-level await if transform is disabled', options: { transforms: { asyncAwait: false } }, input: `const x = await someFunction();`, output: `var x = await someFunction();` }, { description: 'errors on top-level await if transform is enabled', input: `const x = await someFunction();`, error: /Transforming await is not implemented/ }, { description: 'passes through top-level for-await-of if transform is disabled', options: { transforms: { asyncAwait: false, forOf: false } }, input: `for await (const x of someFunction()) { x() }`, output: `for await (var x of someFunction()) { x() }` }, { description: 'errors on top-level for-await-of if transform is enabled', options: { transforms: { asyncAwait: true, dangerousForOf: true } }, input: `for await (const x of someFunction()) { x() }`, error: /Transforming for-await-of statements is not implemented/ } ]; buble-0.19.8/test/samples/binary-and-octal.js000066400000000000000000000011731350705536200210170ustar00rootroot00000000000000module.exports = [ { description: 'transpiles binary numbers', input: ` var num1 = 0b111110111; var num2 = 0B111110111; var str = '0b111110111';`, output: ` var num1 = 503; var num2 = 503; var str = '0b111110111';` }, { description: 'transpiles octal numbers', input: ` var num1 = 0o767; var num2 = 0O767; var str = '0o767';`, output: ` var num1 = 503; var num2 = 503; var str = '0o767';` }, { description: 'can be disabled with `transforms.numericLiteral: false`', options: { transforms: { numericLiteral: false } }, input: '0b111110111', output: '0b111110111' } ]; buble-0.19.8/test/samples/block-scoping.js000066400000000000000000000201601350705536200204220ustar00rootroot00000000000000module.exports = [ { description: 'transpiles let', input: `let x = 'y';`, output: `var x = 'y';` }, { description: 'deconflicts blocks in top-level scope', input: ` if ( a ) { let x = 1; console.log( x ); } else if ( b ) { let x = 2; console.log( x ); } else { let x = 3; console.log( x ); }`, output: ` if ( a ) { var x = 1; console.log( x ); } else if ( b ) { var x$1 = 2; console.log( x$1 ); } else { var x$2 = 3; console.log( x$2 ); }` }, { description: 'deconflicts blocks in same function scope', input: ` var x = 'y'; function foo () { if ( a ) { let x = 1; console.log( x ); } else if ( b ) { let x = 2; console.log( x ); } else { let x = 3; console.log( x ); } }`, output: ` var x = 'y'; function foo () { if ( a ) { var x = 1; console.log( x ); } else if ( b ) { var x$1 = 2; console.log( x$1 ); } else { var x$2 = 3; console.log( x$2 ); } }` }, { description: 'disallows duplicate declarations', input: ` let x = 1; let x = 2; `, error: /Identifier 'x' has already been declared/ }, { description: 'disallows reassignment to constants', input: ` const x = 1; x = 2; `, error: /x is read-only/ }, { description: 'disallows destructured reassignment to constants, short-hand property', input: ` const x = 1; ({ x } = {}); `, error: /x is read-only/ }, { description: 'disallows destructured reassignment to constants, rest property', input: ` const x = 1; ({ ...x } = {}); `, error: /x is read-only/ }, { description: 'disallows destructured reassignment to constants, renamed property', input: ` const x = 1; ({ y: x } = {}); `, error: /x is read-only/ }, { description: 'disallows destructured reassignment to constants, array', input: ` const x = 1; ([ x ] = []); `, error: /x is read-only/ }, { description: 'disallows destructured reassignment to constants, rest element', input: ` const x = 1; ([ ...x ] = []); `, error: /x is read-only/ }, { description: 'disallows updates to constants', input: ` const x = 1; x++; `, error: /x is read-only/ }, { description: 'does not rewrite properties', input: ` var foo = 'x'; if ( true ) { let foo = 'y'; this.foo = 'z'; this[ foo ] = 'q'; }`, output: ` var foo = 'x'; if ( true ) { var foo$1 = 'y'; this.foo = 'z'; this[ foo$1 ] = 'q'; }` }, { description: 'deconflicts with default imports', options: { transforms: { moduleImport: false } }, input: ` import foo from './foo.js'; if ( x ) { let foo = 'y'; console.log( foo ); }`, output: ` import foo from './foo.js'; if ( x ) { var foo$1 = 'y'; console.log( foo$1 ); }` }, { description: 'deconflicts with named imports', options: { transforms: { moduleImport: false } }, input: ` import { foo } from './foo.js'; if ( x ) { let foo = 'y'; console.log( foo ); }`, output: ` import { foo } from './foo.js'; if ( x ) { var foo$1 = 'y'; console.log( foo$1 ); }` }, { description: 'deconflicts with function declarations', input: ` function foo () {} if ( x ) { let foo = 'y'; console.log( foo ); }`, output: ` function foo () {} if ( x ) { var foo$1 = 'y'; console.log( foo$1 ); }` }, { description: 'does not deconflict with function expressions', input: ` var bar = function foo () {}; if ( x ) { let foo = 'y'; console.log( foo ); }`, output: ` var bar = function foo () {}; if ( x ) { var foo = 'y'; console.log( foo ); }` }, { description: 'deconflicts with function expression inside function body', input: ` var bar = function foo () { if ( x ) { let foo = 'y'; console.log( foo ); } };`, output: ` var bar = function foo () { if ( x ) { var foo$1 = 'y'; console.log( foo$1 ); } };` }, { description: 'deconflicts with parameters', input: ` function bar ( foo ) { if ( x ) { let foo = 'y'; console.log( foo ); } }`, output: ` function bar ( foo ) { if ( x ) { var foo$1 = 'y'; console.log( foo$1 ); } }` }, { description: 'deconflicts with class declarations', input: ` class foo {} if ( x ) { let foo = 'y'; console.log( foo ); }`, output: ` var foo = function foo () {}; if ( x ) { var foo$1 = 'y'; console.log( foo$1 ); }` }, { description: 'does not deconflict with class expressions', input: ` var bar = class foo {}; if ( x ) { let foo = 'y'; console.log( foo ); }`, output: ` var bar = /*@__PURE__*/(function () { function foo () {} return foo; }()); if ( x ) { var foo = 'y'; console.log( foo ); }` }, { description: 'deconflicts across multiple function boundaries', input: ` function foo ( x ) { return function () { if ( true ) { const x = 'y'; console.log( x ); } console.log( x ); }; }`, output: ` function foo ( x ) { return function () { if ( true ) { var x$1 = 'y'; console.log( x$1 ); } console.log( x ); }; }` }, { description: 'does not deconflict unnecessarily', input: ` function foo ( x ) { return function () { if ( true ) { const x = 'y'; console.log( x ); } }; }`, output: ` function foo ( x ) { return function () { if ( true ) { var x = 'y'; console.log( x ); } }; }` }, { description: 'deconflicts object pattern declarations', input: ` let x; if ( true ) { let { x, y } = point; console.log( x ); }`, output: ` var x; if ( true ) { var x$1 = point.x; var y = point.y; console.log( x$1 ); }` }, { description: 'deconflicts array pattern declarations', input: ` let x; if ( true ) { let [ x, y ] = point; console.log( x ); }`, output: ` var x; if ( true ) { var x$1 = point[0]; var y = point[1]; console.log( x$1 ); }` }, { description: 'deconflicts rest element declarations', input: ` let x; if ( true ) { let [ first, second, ...x ] = y; console.log( x ); }`, output: ` var x; if ( true ) { var first = y[0]; var second = y[1]; var x$1 = y.slice(2); console.log( x$1 ); }` }, { description: 'can be disabled with `transforms.letConst: false`', options: { transforms: { letConst: false } }, input: ` let a = 1; if ( x ) { let a = 2; console.log( a ); } console.log( a );`, output: ` let a = 1; if ( x ) { let a = 2; console.log( a ); } console.log( a );` }, { description: 'reference preceding declaration (#87)', input: ` if ( x ) { let a = function () { b(); }; let b = function () { alert( 'hello' ); }; a(); b(); }`, output: ` if ( x ) { var a = function () { b(); }; var b = function () { alert( 'hello' ); }; a(); b(); }` }, { description: 'correctly recognizes shadowing of const variables by mutable variables declared after mutation', input: ` const bar = "FAIL"; (function() { function foo() { --bar; bar = ["fail", "PASS", "Fail"][bar]; } let bar = 2; foo(); console.log(bar); }()); `, output: ` var bar = "FAIL"; (function() { function foo() { --bar; bar = ["fail", "PASS", "Fail"][bar]; } var bar = 2; foo(); console.log(bar); }()); ` }, { description: 'correctly transpiles if arrow functions are not transpiled', options: { transforms: { arrow: false } }, input: ` var c; if (true) { let c = prop.end; console.log(c); }`, output: ` var c; if (true) { var c$1 = prop.end; console.log(c$1); }`, }, { description: 'emits correct code after block-less if', input: 'if(0);const e=0', output: 'if(0){ ; }var e=0' } ]; buble-0.19.8/test/samples/classes-no-named-function-expressions.js000066400000000000000000000566471350705536200252470ustar00rootroot00000000000000module.exports = [ { description: 'transpiles a class declaration', options: { namedFunctionExpressions: false }, input: ` class Foo { constructor ( answer ) { this.answer = answer; } }`, output: ` var Foo = function ( answer ) { this.answer = answer; };` }, { description: 'transpiles a class declaration with a non-constructor method', options: { namedFunctionExpressions: false }, input: ` class Foo { constructor ( answer ) { this.answer = answer; } bar ( str ) { return str + 'bar'; } }`, output: ` var Foo = function ( answer ) { this.answer = answer; }; Foo.prototype.bar = function ( str ) { return str + 'bar'; };` }, { description: 'transpiles a class declaration without a constructor function', options: { namedFunctionExpressions: false }, input: ` class Foo { bar ( str ) { return str + 'bar'; } }`, output: ` var Foo = function () {}; Foo.prototype.bar = function ( str ) { return str + 'bar'; };` }, { description: 'no unnecessary deshadowing of method names', options: { namedFunctionExpressions: false }, input: ` var bar = 'x'; class Foo { bar ( str ) { return str + 'bar'; } }`, output: ` var bar = 'x'; var Foo = function () {}; Foo.prototype.bar = function ( str ) { return str + 'bar'; };` }, { description: 'transpiles a class declaration with a static method', options: { namedFunctionExpressions: false }, input: ` class Foo { bar ( str ) { return str + 'bar'; } static baz ( str ) { return str + 'baz'; } }`, output: ` var Foo = function () {}; Foo.prototype.bar = function ( str ) { return str + 'bar'; }; Foo.baz = function ( str ) { return str + 'baz'; };` }, { description: 'transpiles a subclass', options: { namedFunctionExpressions: false }, input: ` class Foo extends Bar { baz ( str ) { return str + 'baz'; } }`, output: ` var Foo = /*@__PURE__*/(function (Bar) { function Foo () { Bar.apply(this, arguments); } if ( Bar ) Foo.__proto__ = Bar; Foo.prototype = Object.create( Bar && Bar.prototype ); Foo.prototype.constructor = Foo; Foo.prototype.baz = function ( str ) { return str + 'baz'; }; return Foo; }(Bar));` }, { description: 'transpiles a subclass with super calls', options: { namedFunctionExpressions: false }, input: ` class Foo extends Bar { constructor ( x ) { super( x ); this.y = 'z'; } baz ( a, b, c ) { super.baz( a, b, c ); } }`, output: ` var Foo = /*@__PURE__*/(function (Bar) { function Foo ( x ) { Bar.call( this, x ); this.y = 'z'; } if ( Bar ) Foo.__proto__ = Bar; Foo.prototype = Object.create( Bar && Bar.prototype ); Foo.prototype.constructor = Foo; Foo.prototype.baz = function ( a, b, c ) { Bar.prototype.baz.call( this, a, b, c ); }; return Foo; }(Bar));` }, { description: 'transpiles a subclass with super calls with spread arguments', options: { namedFunctionExpressions: false }, input: ` class Foo extends Bar { baz ( ...args ) { super.baz(...args); } boz ( x, y, ...z ) { super.boz(x, y, ...z); } fab ( x, ...y ) { super.qux(...x, ...y); } fob ( x, y, ...z ) { ((x, y, z) => super.qux(x, ...y, ...z))(x, y, z); } }`, output: ` var Foo = /*@__PURE__*/(function (Bar) { function Foo () { Bar.apply(this, arguments); } if ( Bar ) Foo.__proto__ = Bar; Foo.prototype = Object.create( Bar && Bar.prototype ); Foo.prototype.constructor = Foo; Foo.prototype.baz = function () { var args = [], len = arguments.length; while ( len-- ) args[ len ] = arguments[ len ]; Bar.prototype.baz.apply(this, args); }; Foo.prototype.boz = function ( x, y ) { var z = [], len = arguments.length - 2; while ( len-- > 0 ) z[ len ] = arguments[ len + 2 ]; Bar.prototype.boz.apply(this, [ x, y ].concat( z )); }; Foo.prototype.fab = function ( x ) { var y = [], len = arguments.length - 1; while ( len-- > 0 ) y[ len ] = arguments[ len + 1 ]; Bar.prototype.qux.apply(this, x.concat( y )); }; Foo.prototype.fob = function ( x, y ) { var this$1 = this; var z = [], len = arguments.length - 2; while ( len-- > 0 ) z[ len ] = arguments[ len + 2 ]; (function (x, y, z) { return Bar.prototype.qux.apply(this$1, [ x ].concat( y, z )); })(x, y, z); }; return Foo; }(Bar));` }, { description: 'transpiles export default class', options: { transforms: { moduleExport: false }, namedFunctionExpressions: false }, input: ` export default class Foo { bar () {} }`, output: ` var Foo = function () {}; Foo.prototype.bar = function () {}; export default Foo;` }, { description: 'transpiles export default subclass', options: { transforms: { moduleExport: false }, namedFunctionExpressions: false }, input: ` export default class Foo extends Bar { bar () {} }`, output: ` var Foo = /*@__PURE__*/(function (Bar) { function Foo () { Bar.apply(this, arguments); } if ( Bar ) Foo.__proto__ = Bar; Foo.prototype = Object.create( Bar && Bar.prototype ); Foo.prototype.constructor = Foo; Foo.prototype.bar = function () {}; return Foo; }(Bar)); export default Foo;` }, { description: 'transpiles export default subclass with subsequent statement', options: { transforms: { moduleExport: false }, namedFunctionExpressions: false }, input: ` export default class Foo extends Bar { bar () {} } new Foo().bar();`, output: ` var Foo = /*@__PURE__*/(function (Bar) { function Foo () { Bar.apply(this, arguments); } if ( Bar ) Foo.__proto__ = Bar; Foo.prototype = Object.create( Bar && Bar.prototype ); Foo.prototype.constructor = Foo; Foo.prototype.bar = function () {}; return Foo; }(Bar)); export default Foo; new Foo().bar();` }, { description: 'transpiles empty class', options: { namedFunctionExpressions: false }, input: `class Foo {}`, output: `var Foo = function () {};` }, { description: 'transpiles an anonymous empty class expression', options: { namedFunctionExpressions: false }, input: ` var Foo = class {};`, output: ` var Foo = /*@__PURE__*/(function () { function Foo () {} return Foo; }());` }, { description: 'transpiles an anonymous class expression with a constructor', options: { namedFunctionExpressions: false }, input: ` var Foo = class { constructor ( x ) { this.x = x; } };`, output: ` var Foo = /*@__PURE__*/(function () { function Foo ( x ) { this.x = x; } return Foo; }());` }, { description: 'transpiles an anonymous class expression with a non-constructor method', options: { namedFunctionExpressions: false }, input: ` var Foo = class { bar ( x ) { console.log( x ); } };`, output: ` var Foo = /*@__PURE__*/(function () { function Foo () {} Foo.prototype.bar = function ( x ) { console.log( x ); }; return Foo; }());` }, { description: 'allows constructor to be in middle of body', options: { namedFunctionExpressions: false }, input: ` class Foo { before () { // code goes here } constructor () { // constructor goes here } after () { // code goes here } }`, output: ` var Foo = function () { // constructor goes here }; Foo.prototype.before = function () { // code goes here }; Foo.prototype.after = function () { // code goes here };` }, { description: 'allows constructor to be at end of body', options: { namedFunctionExpressions: false }, input: ` class Foo { before () { // code goes here } constructor () { // constructor goes here } }`, output: ` var Foo = function () { // constructor goes here }; Foo.prototype.before = function () { // code goes here };` }, { description: 'transpiles getters and setters', options: { namedFunctionExpressions: false }, input: ` class Circle { constructor ( radius ) { this.radius = radius; } get area () { return Math.PI * Math.pow( this.radius, 2 ); } set area ( area ) { this.radius = Math.sqrt( area / Math.PI ); } static get description () { return 'round'; } }`, output: ` var Circle = function ( radius ) { this.radius = radius; }; var prototypeAccessors = { area: { configurable: true } }; var staticAccessors = { description: { configurable: true } }; prototypeAccessors.area.get = function () { return Math.PI * Math.pow( this.radius, 2 ); }; prototypeAccessors.area.set = function ( area ) { this.radius = Math.sqrt( area / Math.PI ); }; staticAccessors.description.get = function () { return 'round'; }; Object.defineProperties( Circle.prototype, prototypeAccessors ); Object.defineProperties( Circle, staticAccessors );` }, { description: 'transpiles getters and setters in subclass', options: { namedFunctionExpressions: false }, input: ` class Circle extends Shape { constructor ( radius ) { super(); this.radius = radius; } get area () { return Math.PI * Math.pow( this.radius, 2 ); } set area ( area ) { this.radius = Math.sqrt( area / Math.PI ); } static get description () { return 'round'; } }`, output: ` var Circle = /*@__PURE__*/(function (Shape) { function Circle ( radius ) { Shape.call(this); this.radius = radius; } if ( Shape ) Circle.__proto__ = Shape; Circle.prototype = Object.create( Shape && Shape.prototype ); Circle.prototype.constructor = Circle; var prototypeAccessors = { area: { configurable: true } }; var staticAccessors = { description: { configurable: true } }; prototypeAccessors.area.get = function () { return Math.PI * Math.pow( this.radius, 2 ); }; prototypeAccessors.area.set = function ( area ) { this.radius = Math.sqrt( area / Math.PI ); }; staticAccessors.description.get = function () { return 'round'; }; Object.defineProperties( Circle.prototype, prototypeAccessors ); Object.defineProperties( Circle, staticAccessors ); return Circle; }(Shape));` }, { description: 'can be disabled with `transforms.classes: false`', options: { namedFunctionExpressions: false, transforms: { classes: false } }, input: ` class Foo extends Bar { constructor ( answer ) { super(); this.answer = answer; } }`, output: ` class Foo extends Bar { constructor ( answer ) { super(); this.answer = answer; } }` }, { description: 'declaration extends from an expression (#15)', options: { namedFunctionExpressions: false }, input: ` const q = {a: class {}}; class b extends q.a { c () {} }`, output: ` var q = {a: /*@__PURE__*/(function () { function anonymous () {} return anonymous; }())}; var b = /*@__PURE__*/(function (superclass) { function b () { superclass.apply(this, arguments); } if ( superclass ) b.__proto__ = superclass; b.prototype = Object.create( superclass && superclass.prototype ); b.prototype.constructor = b; b.prototype.c = function () {}; return b; }(q.a));` }, { description: 'expression extends from an expression (#15)', options: { namedFunctionExpressions: false }, input: ` const q = {a: class {}}; const b = class b extends q.a { c () {} };`, output: ` var q = {a: /*@__PURE__*/(function () { function anonymous () {} return anonymous; }())}; var b = /*@__PURE__*/(function (superclass) { function b () { superclass.apply(this, arguments); } if ( superclass ) b.__proto__ = superclass; b.prototype = Object.create( superclass && superclass.prototype ); b.prototype.constructor = b; b.prototype.c = function () {}; return b; }(q.a));` }, { description: 'expression extends from an expression with super calls (#31)', options: { namedFunctionExpressions: false }, input: ` class b extends x.y.z { constructor() { super(); } }`, output: ` var b = /*@__PURE__*/(function (superclass) { function b() { superclass.call(this); } if ( superclass ) b.__proto__ = superclass; b.prototype = Object.create( superclass && superclass.prototype ); b.prototype.constructor = b; return b; }(x.y.z));` }, { description: 'anonymous expression extends named class (#31)', options: { namedFunctionExpressions: false }, input: ` SubClass = class extends SuperClass { constructor() { super(); } };`, output: ` SubClass = /*@__PURE__*/(function (SuperClass) { function SubClass() { SuperClass.call(this); } if ( SuperClass ) SubClass.__proto__ = SuperClass; SubClass.prototype = Object.create( SuperClass && SuperClass.prototype ); SubClass.prototype.constructor = SubClass; return SubClass; }(SuperClass));` }, { description: 'verify deindent() does not corrupt string literals in class methods (#159)', options: { namedFunctionExpressions: false }, input: ` class Foo { bar() { var s = "0\t1\t\t2\t\t\t3\t\t\t\t4\t\t\t\t\t5"; return s + '\t'; } baz() { return \`\t\`; } } `, output: ` var Foo = function () {}; Foo.prototype.bar = function () { var s = "0\t1\t\t2\t\t\t3\t\t\t\t4\t\t\t\t\t5"; return s + '\t'; }; Foo.prototype.baz = function () { return "\\t"; }; ` }, { description: 'deindents a function body with destructuring (#22)', options: { namedFunctionExpressions: false }, input: ` class Foo { constructor ( options ) { const { a, b } = options; } }`, output: ` var Foo = function ( options ) { var a = options.a; var b = options.b; };` }, { description: 'allows super in static methods', options: { namedFunctionExpressions: false }, input: ` class Foo extends Bar { static baz () { super.baz(); } }`, output: ` var Foo = /*@__PURE__*/(function (Bar) { function Foo () { Bar.apply(this, arguments); } if ( Bar ) Foo.__proto__ = Bar; Foo.prototype = Object.create( Bar && Bar.prototype ); Foo.prototype.constructor = Foo; Foo.baz = function () { Bar.baz.call(this); }; return Foo; }(Bar));` }, { description: 'allows zero space between class id and body (#46)', options: { namedFunctionExpressions: false }, input: ` class A{ x(){} } var B = class B{ x(){} }; class C extends D{ x(){} } var E = class E extends F{ x(){} }`, output: ` var A = function () {}; A.prototype.x = function (){}; var B = /*@__PURE__*/(function () { function B () {} B.prototype.x = function (){}; return B; }()); var C = /*@__PURE__*/(function (D) { function C () { D.apply(this, arguments); } if ( D ) C.__proto__ = D; C.prototype = Object.create( D && D.prototype ); C.prototype.constructor = C; C.prototype.x = function (){}; return C; }(D)); var E = /*@__PURE__*/(function (F) { function E () { F.apply(this, arguments); } if ( F ) E.__proto__ = F; E.prototype = Object.create( F && F.prototype ); E.prototype.constructor = E; E.prototype.x = function (){}; return E; }(F))` }, { description: 'transpiles a class with an accessor and no constructor (#48)', options: { namedFunctionExpressions: false }, input: ` class Foo { static get bar() { return 'baz' } }`, output: ` var Foo = function () {}; var staticAccessors = { bar: { configurable: true } }; staticAccessors.bar.get = function () { return 'baz' }; Object.defineProperties( Foo, staticAccessors );` }, { description: 'uses correct indentation for inserted statements in constructor (#39)', options: { namedFunctionExpressions: false }, input: ` class Foo { constructor ( options, { a2, b2 } ) { const { a, b } = options; const render = () => { requestAnimationFrame( render ); this.render(); }; render(); } render () { // code goes here... } }`, output: ` var Foo = function ( options, ref ) { var this$1 = this; var a2 = ref.a2; var b2 = ref.b2; var a = options.a; var b = options.b; var render = function () { requestAnimationFrame( render ); this$1.render(); }; render(); }; Foo.prototype.render = function () { // code goes here... };` }, { description: 'uses correct indentation for inserted statements in subclass constructor (#39)', options: { namedFunctionExpressions: false }, input: ` class Foo extends Bar { constructor ( options, { a2, b2 } ) { super(); const { a, b } = options; const render = () => { requestAnimationFrame( render ); this.render(); }; render(); } render () { // code goes here... } }`, output: ` var Foo = /*@__PURE__*/(function (Bar) { function Foo ( options, ref ) { var this$1 = this; var a2 = ref.a2; var b2 = ref.b2; Bar.call(this); var a = options.a; var b = options.b; var render = function () { requestAnimationFrame( render ); this$1.render(); }; render(); } if ( Bar ) Foo.__proto__ = Bar; Foo.prototype = Object.create( Bar && Bar.prototype ); Foo.prototype.constructor = Foo; Foo.prototype.render = function () { // code goes here... }; return Foo; }(Bar));` }, { description: 'allows subclass to use rest parameters', options: { namedFunctionExpressions: false }, input: ` class SubClass extends SuperClass { constructor( ...args ) { super( ...args ); } }`, output: ` var SubClass = /*@__PURE__*/(function (SuperClass) { function SubClass() { var args = [], len = arguments.length; while ( len-- ) args[ len ] = arguments[ len ]; SuperClass.apply( this, args ); } if ( SuperClass ) SubClass.__proto__ = SuperClass; SubClass.prototype = Object.create( SuperClass && SuperClass.prototype ); SubClass.prototype.constructor = SubClass; return SubClass; }(SuperClass));` }, { description: 'allows subclass to use rest parameters with other arguments', options: { namedFunctionExpressions: false }, input: ` class SubClass extends SuperClass { constructor( ...args ) { super( 1, ...args, 2 ); } }`, output: ` var SubClass = /*@__PURE__*/(function (SuperClass) { function SubClass() { var args = [], len = arguments.length; while ( len-- ) args[ len ] = arguments[ len ]; SuperClass.apply( this, [ 1 ].concat( args, [2] ) ); } if ( SuperClass ) SubClass.__proto__ = SuperClass; SubClass.prototype = Object.create( SuperClass && SuperClass.prototype ); SubClass.prototype.constructor = SubClass; return SubClass; }(SuperClass));` }, { description: 'transpiles computed class properties', options: { namedFunctionExpressions: false }, input: ` class Foo { [a.b.c] () { // code goes here } }`, output: ` var Foo = function () {}; Foo.prototype[a.b.c] = function () { // code goes here };` }, { description: 'transpiles static computed class properties', options: { namedFunctionExpressions: false }, input: ` class Foo { static [a.b.c] () { // code goes here } }`, output: ` var Foo = function () {}; Foo[a.b.c] = function () { // code goes here };` }, { skip: true, description: 'transpiles computed class accessors', options: { namedFunctionExpressions: false }, input: ` class Foo { get [a.b.c] () { // code goes here } }`, output: ` var Foo = function () {}; var prototypeAccessors = {}; var ref = a.b.c; prototypeAccessors[ref] = {}; prototypeAccessors[ref].get = function () { // code goes here }; Object.defineProperties( Foo.prototype, prototypeAccessors );` }, { description: 'transpiles reserved class properties (!68)', options: { namedFunctionExpressions: false }, input: ` class Foo { catch () { // code goes here } }`, output: ` var Foo = function () {}; Foo.prototype.catch = function () { // code goes here };` }, { description: 'transpiles static reserved class properties (!68)', options: { namedFunctionExpressions: false }, input: ` class Foo { static catch () { // code goes here } }`, output: ` var Foo = function () {}; Foo.catch = function () { // code goes here };` }, { description: 'uses correct `this` when transpiling `super` (#89)', options: { namedFunctionExpressions: false }, input: ` class A extends B { constructor () { super(); this.doSomething(() => { super.doSomething(); }); } }`, output: ` var A = /*@__PURE__*/(function (B) { function A () { var this$1 = this; B.call(this); this.doSomething(function () { B.prototype.doSomething.call(this$1); }); } if ( B ) A.__proto__ = B; A.prototype = Object.create( B && B.prototype ); A.prototype.constructor = A; return A; }(B));` }, { description: 'methods with computed names', options: { namedFunctionExpressions: false }, input: ` class A { [x](){} [0](){} [1 + 2](){} [normal + " Method"](){} } `, output: ` var A = function () {}; A.prototype[x] = function (){}; A.prototype[0] = function (){}; A.prototype[1 + 2] = function (){}; A.prototype[normal + " Method"] = function (){}; ` }, { description: 'static methods with computed names with varied spacing (#139)', options: { namedFunctionExpressions: false }, input: ` class B { static[.000004](){} static [x](){} static [x-y](){} static[\`Static computed \${name}\`](){} } `, output: ` var B = function () {}; B[.000004] = function (){}; B[x] = function (){}; B[x-y] = function (){}; B[("Static computed " + name)] = function (){}; ` }, { description: 'methods with numeric or string names (#139)', options: { namedFunctionExpressions: false }, input: ` class C { 0(){} 0b101(){} 80(){} .12e3(){} 0o753(){} 12e34(){} 0xFFFF(){} "var"(){} } `, output: ` var C = function () {}; C.prototype[0] = function (){}; C.prototype[5] = function (){}; C.prototype[80] = function (){}; C.prototype[.12e3] = function (){}; C.prototype[491] = function (){}; C.prototype[12e34] = function (){}; C.prototype[0xFFFF] = function (){}; C.prototype["var"] = function (){}; ` }, { description: 'static methods with numeric or string names with varied spacing (#139)', options: { namedFunctionExpressions: false }, input: ` class D { static .75(){} static"Static Method"(){} static "foo"(){} } `, output: ` var D = function () {}; D[.75] = function (){}; D["Static Method"] = function (){}; D["foo"] = function (){}; ` } // TODO more tests. e.g. getters and setters. // 'super.*' is not allowed before super() ]; buble-0.19.8/test/samples/classes.js000066400000000000000000000552451350705536200173410ustar00rootroot00000000000000module.exports = [ { description: 'transpiles a class declaration', input: ` class Foo { constructor ( answer ) { this.answer = answer; } }`, output: ` var Foo = function Foo ( answer ) { this.answer = answer; };` }, { description: 'transpiles a class declaration with a non-constructor method', input: ` class Foo { constructor ( answer ) { this.answer = answer; } bar ( str ) { return str + 'bar'; } }`, output: ` var Foo = function Foo ( answer ) { this.answer = answer; }; Foo.prototype.bar = function bar ( str ) { return str + 'bar'; };` }, { description: 'transpiles a class declaration without a constructor function', input: ` class Foo { bar ( str ) { return str + 'bar'; } }`, output: ` var Foo = function Foo () {}; Foo.prototype.bar = function bar ( str ) { return str + 'bar'; };` }, { description: 'no unnecessary deshadowing of method names', input: ` var bar = 'x'; class Foo { bar ( str ) { return str + 'bar'; } }`, output: ` var bar = 'x'; var Foo = function Foo () {}; Foo.prototype.bar = function bar ( str ) { return str + 'bar'; };` }, { description: 'transpiles a class declaration with a static method', input: ` class Foo { bar ( str ) { return str + 'bar'; } static baz ( str ) { return str + 'baz'; } }`, output: ` var Foo = function Foo () {}; Foo.prototype.bar = function bar ( str ) { return str + 'bar'; }; Foo.baz = function baz ( str ) { return str + 'baz'; };` }, { description: 'transpiles a subclass', input: ` class Foo extends Bar { baz ( str ) { return str + 'baz'; } }`, output: ` var Foo = /*@__PURE__*/(function (Bar) { function Foo () { Bar.apply(this, arguments); } if ( Bar ) Foo.__proto__ = Bar; Foo.prototype = Object.create( Bar && Bar.prototype ); Foo.prototype.constructor = Foo; Foo.prototype.baz = function baz ( str ) { return str + 'baz'; }; return Foo; }(Bar));` }, { description: 'transpiles a subclass with super calls', input: ` class Foo extends Bar { constructor ( x ) { super( x ); this.y = 'z'; } baz ( a, b, c ) { super.baz( a, b, c ); } }`, output: ` var Foo = /*@__PURE__*/(function (Bar) { function Foo ( x ) { Bar.call( this, x ); this.y = 'z'; } if ( Bar ) Foo.__proto__ = Bar; Foo.prototype = Object.create( Bar && Bar.prototype ); Foo.prototype.constructor = Foo; Foo.prototype.baz = function baz ( a, b, c ) { Bar.prototype.baz.call( this, a, b, c ); }; return Foo; }(Bar));` }, { description: 'transpiles a subclass with super calls with spread arguments', input: ` class Foo extends Bar { baz ( ...args ) { super.baz(...args); } boz ( x, y, ...z ) { super.boz(x, y, ...z); } fab ( x, ...y ) { super.qux(...x, ...y); } fob ( x, y, ...z ) { ((x, y, z) => super.qux(x, ...y, ...z))(x, y, z); } }`, output: ` var Foo = /*@__PURE__*/(function (Bar) { function Foo () { Bar.apply(this, arguments); } if ( Bar ) Foo.__proto__ = Bar; Foo.prototype = Object.create( Bar && Bar.prototype ); Foo.prototype.constructor = Foo; Foo.prototype.baz = function baz () { var args = [], len = arguments.length; while ( len-- ) args[ len ] = arguments[ len ]; Bar.prototype.baz.apply(this, args); }; Foo.prototype.boz = function boz ( x, y ) { var z = [], len = arguments.length - 2; while ( len-- > 0 ) z[ len ] = arguments[ len + 2 ]; Bar.prototype.boz.apply(this, [ x, y ].concat( z )); }; Foo.prototype.fab = function fab ( x ) { var y = [], len = arguments.length - 1; while ( len-- > 0 ) y[ len ] = arguments[ len + 1 ]; Bar.prototype.qux.apply(this, x.concat( y )); }; Foo.prototype.fob = function fob ( x, y ) { var this$1 = this; var z = [], len = arguments.length - 2; while ( len-- > 0 ) z[ len ] = arguments[ len + 2 ]; (function (x, y, z) { return Bar.prototype.qux.apply(this$1, [ x ].concat( y, z )); })(x, y, z); }; return Foo; }(Bar));` }, { description: 'transpiles export default class', options: { transforms: { moduleExport: false } }, input: ` export default class Foo { bar () {} }`, output: ` var Foo = function Foo () {}; Foo.prototype.bar = function bar () {}; export default Foo;` }, { description: 'transpiles export default subclass', options: { transforms: { moduleExport: false } }, input: ` export default class Foo extends Bar { bar () {} }`, output: ` var Foo = /*@__PURE__*/(function (Bar) { function Foo () { Bar.apply(this, arguments); } if ( Bar ) Foo.__proto__ = Bar; Foo.prototype = Object.create( Bar && Bar.prototype ); Foo.prototype.constructor = Foo; Foo.prototype.bar = function bar () {}; return Foo; }(Bar)); export default Foo;` }, { description: 'transpiles export default subclass with subsequent statement', options: { transforms: { moduleExport: false } }, input: ` export default class Foo extends Bar { bar () {} } new Foo().bar();`, output: ` var Foo = /*@__PURE__*/(function (Bar) { function Foo () { Bar.apply(this, arguments); } if ( Bar ) Foo.__proto__ = Bar; Foo.prototype = Object.create( Bar && Bar.prototype ); Foo.prototype.constructor = Foo; Foo.prototype.bar = function bar () {}; return Foo; }(Bar)); export default Foo; new Foo().bar();` }, { description: 'transpiles empty class', input: `class Foo {}`, output: `var Foo = function Foo () {};` }, { description: 'transpiles an anonymous empty class expression', input: ` var Foo = class {};`, output: ` var Foo = /*@__PURE__*/(function () { function Foo () {} return Foo; }());` }, { description: 'transpiles an anonymous class expression with a constructor', input: ` var Foo = class { constructor ( x ) { this.x = x; } };`, output: ` var Foo = /*@__PURE__*/(function () { function Foo ( x ) { this.x = x; } return Foo; }());` }, { description: 'transpiles an anonymous class expression with a non-constructor method', input: ` var Foo = class { bar ( x ) { console.log( x ); } };`, output: ` var Foo = /*@__PURE__*/(function () { function Foo () {} Foo.prototype.bar = function bar ( x ) { console.log( x ); }; return Foo; }());` }, { description: 'transpiles an anonymous class expression that is assigned to a property', input: ` const q = {}; q.a = class { c () {} };`, output: ` var q = {}; q.a = /*@__PURE__*/(function () { function a () {} a.prototype.c = function c () {}; return a; }());` }, { description: 'allows constructor to be in middle of body', input: ` class Foo { before () { // code goes here } constructor () { // constructor goes here } after () { // code goes here } }`, output: ` var Foo = function Foo () { // constructor goes here }; Foo.prototype.before = function before () { // code goes here }; Foo.prototype.after = function after () { // code goes here };` }, { description: 'allows constructor to be at end of body', input: ` class Foo { before () { // code goes here } constructor () { // constructor goes here } }`, output: ` var Foo = function Foo () { // constructor goes here }; Foo.prototype.before = function before () { // code goes here };` }, { description: 'transpiles getters and setters', input: ` class Circle { constructor ( radius ) { this.radius = radius; } get area () { return Math.PI * Math.pow( this.radius, 2 ); } set area ( area ) { this.radius = Math.sqrt( area / Math.PI ); } static get description () { return 'round'; } }`, output: ` var Circle = function Circle ( radius ) { this.radius = radius; }; var prototypeAccessors = { area: { configurable: true } }; var staticAccessors = { description: { configurable: true } }; prototypeAccessors.area.get = function () { return Math.PI * Math.pow( this.radius, 2 ); }; prototypeAccessors.area.set = function ( area ) { this.radius = Math.sqrt( area / Math.PI ); }; staticAccessors.description.get = function () { return 'round'; }; Object.defineProperties( Circle.prototype, prototypeAccessors ); Object.defineProperties( Circle, staticAccessors );` }, { description: 'transpiles getters and setters in subclass', input: ` class Circle extends Shape { constructor ( radius ) { super(); this.radius = radius; } get area () { return Math.PI * Math.pow( this.radius, 2 ); } set area ( area ) { this.radius = Math.sqrt( area / Math.PI ); } static get description () { return 'round'; } }`, output: ` var Circle = /*@__PURE__*/(function (Shape) { function Circle ( radius ) { Shape.call(this); this.radius = radius; } if ( Shape ) Circle.__proto__ = Shape; Circle.prototype = Object.create( Shape && Shape.prototype ); Circle.prototype.constructor = Circle; var prototypeAccessors = { area: { configurable: true } }; var staticAccessors = { description: { configurable: true } }; prototypeAccessors.area.get = function () { return Math.PI * Math.pow( this.radius, 2 ); }; prototypeAccessors.area.set = function ( area ) { this.radius = Math.sqrt( area / Math.PI ); }; staticAccessors.description.get = function () { return 'round'; }; Object.defineProperties( Circle.prototype, prototypeAccessors ); Object.defineProperties( Circle, staticAccessors ); return Circle; }(Shape));` }, { description: 'can be disabled with `transforms.classes: false`', options: { transforms: { classes: false } }, input: ` class Foo extends Bar { constructor ( answer ) { super(); this.answer = answer; } }`, output: ` class Foo extends Bar { constructor ( answer ) { super(); this.answer = answer; } }` }, { description: 'declaration extends from an expression (#15)', input: ` const q = {a: class {}}; class b extends q.a { c () {} }`, output: ` var q = {a: /*@__PURE__*/(function () { function anonymous () {} return anonymous; }())}; var b = /*@__PURE__*/(function (superclass) { function b () { superclass.apply(this, arguments); } if ( superclass ) b.__proto__ = superclass; b.prototype = Object.create( superclass && superclass.prototype ); b.prototype.constructor = b; b.prototype.c = function c () {}; return b; }(q.a));` }, { description: 'expression extends from an expression (#15)', input: ` const q = {a: class {}}; const b = class b extends q.a { c () {} };`, output: ` var q = {a: /*@__PURE__*/(function () { function anonymous () {} return anonymous; }())}; var b = /*@__PURE__*/(function (superclass) { function b () { superclass.apply(this, arguments); } if ( superclass ) b.__proto__ = superclass; b.prototype = Object.create( superclass && superclass.prototype ); b.prototype.constructor = b; b.prototype.c = function c () {}; return b; }(q.a));` }, { description: 'expression extends from an expression with super calls (#31)', input: ` class b extends x.y.z { constructor() { super(); } }`, output: ` var b = /*@__PURE__*/(function (superclass) { function b() { superclass.call(this); } if ( superclass ) b.__proto__ = superclass; b.prototype = Object.create( superclass && superclass.prototype ); b.prototype.constructor = b; return b; }(x.y.z));` }, { description: 'anonymous expression extends named class (#31)', input: ` SubClass = class extends SuperClass { constructor() { super(); } };`, output: ` SubClass = /*@__PURE__*/(function (SuperClass) { function SubClass() { SuperClass.call(this); } if ( SuperClass ) SubClass.__proto__ = SuperClass; SubClass.prototype = Object.create( SuperClass && SuperClass.prototype ); SubClass.prototype.constructor = SubClass; return SubClass; }(SuperClass));` }, { description: 'verify deindent() does not corrupt string literals in class methods (#159)', input: ` class Foo { bar() { var s = "0\t1\t\t2\t\t\t3\t\t\t\t4\t\t\t\t\t5"; return s + '\t'; } baz() { return \`\t\`; } } `, output: ` var Foo = function Foo () {}; Foo.prototype.bar = function bar () { var s = "0\t1\t\t2\t\t\t3\t\t\t\t4\t\t\t\t\t5"; return s + '\t'; }; Foo.prototype.baz = function baz () { return "\\t"; }; ` }, { description: 'deindents a function body with destructuring (#22)', input: ` class Foo { constructor ( options ) { const { a, b } = options; } }`, output: ` var Foo = function Foo ( options ) { var a = options.a; var b = options.b; };` }, { description: 'allows super in static methods', input: ` class Foo extends Bar { static baz () { super.baz(); } }`, output: ` var Foo = /*@__PURE__*/(function (Bar) { function Foo () { Bar.apply(this, arguments); } if ( Bar ) Foo.__proto__ = Bar; Foo.prototype = Object.create( Bar && Bar.prototype ); Foo.prototype.constructor = Foo; Foo.baz = function baz () { Bar.baz.call(this); }; return Foo; }(Bar));` }, { description: 'allows zero space between class id and body (#46)', input: ` class A{ x(){} } var B = class B{ x(){} }; class C extends D{ x(){} } var E = class E extends F{ x(){} }`, output: ` var A = function A () {}; A.prototype.x = function x (){}; var B = /*@__PURE__*/(function () { function B () {} B.prototype.x = function x (){}; return B; }()); var C = /*@__PURE__*/(function (D) { function C () { D.apply(this, arguments); } if ( D ) C.__proto__ = D; C.prototype = Object.create( D && D.prototype ); C.prototype.constructor = C; C.prototype.x = function x (){}; return C; }(D)); var E = /*@__PURE__*/(function (F) { function E () { F.apply(this, arguments); } if ( F ) E.__proto__ = F; E.prototype = Object.create( F && F.prototype ); E.prototype.constructor = E; E.prototype.x = function x (){}; return E; }(F))` }, { description: 'transpiles a class with an accessor and no constructor (#48)', input: ` class Foo { static get bar() { return 'baz' } }`, output: ` var Foo = function Foo () {}; var staticAccessors = { bar: { configurable: true } }; staticAccessors.bar.get = function () { return 'baz' }; Object.defineProperties( Foo, staticAccessors );` }, { description: 'uses correct indentation for inserted statements in constructor (#39)', input: ` class Foo { constructor ( options, { a2, b2 } ) { const { a, b } = options; const render = () => { requestAnimationFrame( render ); this.render(); }; render(); } render () { // code goes here... } }`, output: ` var Foo = function Foo ( options, ref ) { var this$1 = this; var a2 = ref.a2; var b2 = ref.b2; var a = options.a; var b = options.b; var render = function () { requestAnimationFrame( render ); this$1.render(); }; render(); }; Foo.prototype.render = function render () { // code goes here... };` }, { description: 'uses correct indentation for inserted statements in subclass constructor (#39)', input: ` class Foo extends Bar { constructor ( options, { a2, b2 } ) { super(); const { a, b } = options; const render = () => { requestAnimationFrame( render ); this.render(); }; render(); } render () { // code goes here... } }`, output: ` var Foo = /*@__PURE__*/(function (Bar) { function Foo ( options, ref ) { var this$1 = this; var a2 = ref.a2; var b2 = ref.b2; Bar.call(this); var a = options.a; var b = options.b; var render = function () { requestAnimationFrame( render ); this$1.render(); }; render(); } if ( Bar ) Foo.__proto__ = Bar; Foo.prototype = Object.create( Bar && Bar.prototype ); Foo.prototype.constructor = Foo; Foo.prototype.render = function render () { // code goes here... }; return Foo; }(Bar));` }, { description: 'allows subclass to use rest parameters', input: ` class SubClass extends SuperClass { constructor( ...args ) { super( ...args ); } }`, output: ` var SubClass = /*@__PURE__*/(function (SuperClass) { function SubClass() { var args = [], len = arguments.length; while ( len-- ) args[ len ] = arguments[ len ]; SuperClass.apply( this, args ); } if ( SuperClass ) SubClass.__proto__ = SuperClass; SubClass.prototype = Object.create( SuperClass && SuperClass.prototype ); SubClass.prototype.constructor = SubClass; return SubClass; }(SuperClass));` }, { description: 'allows subclass to use rest parameters with other arguments', input: ` class SubClass extends SuperClass { constructor( ...args ) { super( 1, ...args, 2 ); } }`, output: ` var SubClass = /*@__PURE__*/(function (SuperClass) { function SubClass() { var args = [], len = arguments.length; while ( len-- ) args[ len ] = arguments[ len ]; SuperClass.apply( this, [ 1 ].concat( args, [2] ) ); } if ( SuperClass ) SubClass.__proto__ = SuperClass; SubClass.prototype = Object.create( SuperClass && SuperClass.prototype ); SubClass.prototype.constructor = SubClass; return SubClass; }(SuperClass));` }, { description: 'transpiles computed class properties', input: ` class Foo { [a.b.c] () { // code goes here } }`, output: ` var Foo = function Foo () {}; Foo.prototype[a.b.c] = function () { // code goes here };` }, { description: 'transpiles static computed class properties', input: ` class Foo { static [a.b.c] () { // code goes here } }`, output: ` var Foo = function Foo () {}; Foo[a.b.c] = function () { // code goes here };` }, { skip: true, description: 'transpiles computed class accessors', input: ` class Foo { get [a.b.c] () { // code goes here } }`, output: ` var Foo = function Foo () {}; var prototypeAccessors = {}; var ref = a.b.c; prototypeAccessors[ref] = {}; prototypeAccessors[ref].get = function () { // code goes here }; Object.defineProperties( Foo.prototype, prototypeAccessors );` }, { description: 'transpiles reserved class properties (!68)', input: ` class Foo { catch () { // code goes here } }`, output: ` var Foo = function Foo () {}; Foo.prototype.catch = function catch$1 () { // code goes here };` }, { description: 'transpiles static reserved class properties (!68)', input: ` class Foo { static catch () { // code goes here } }`, output: ` var Foo = function Foo () {}; Foo.catch = function catch$1 () { // code goes here };` }, { description: 'uses correct `this` when transpiling `super` (#89)', input: ` class A extends B { constructor () { super(); this.doSomething(() => { super.doSomething(); }); } }`, output: ` var A = /*@__PURE__*/(function (B) { function A () { var this$1 = this; B.call(this); this.doSomething(function () { B.prototype.doSomething.call(this$1); }); } if ( B ) A.__proto__ = B; A.prototype = Object.create( B && B.prototype ); A.prototype.constructor = A; return A; }(B));` }, { description: 'methods with computed names', input: ` class A { [x](){} [0](){} [1 + 2](){} [normal + " Method"](){} } `, output: ` var A = function A () {}; A.prototype[x] = function (){}; A.prototype[0] = function (){}; A.prototype[1 + 2] = function (){}; A.prototype[normal + " Method"] = function (){}; ` }, { description: 'static methods with computed names with varied spacing (#139)', input: ` class B { static[.000004](){} static [x](){} static [x-y](){} static[\`Static computed \${name}\`](){} } `, output: ` var B = function B () {}; B[.000004] = function (){}; B[x] = function (){}; B[x-y] = function (){}; B[("Static computed " + name)] = function (){}; ` }, { description: 'methods with numeric or string names (#139)', input: ` class C { 0(){} 0b101(){} 80(){} .12e3(){} 0o753(){} 12e34(){} 0xFFFF(){} "var"(){} } `, output: ` var C = function C () {}; C.prototype[0] = function (){}; C.prototype[5] = function (){}; C.prototype[80] = function (){}; C.prototype[.12e3] = function (){}; C.prototype[491] = function (){}; C.prototype[12e34] = function (){}; C.prototype[0xFFFF] = function (){}; C.prototype["var"] = function (){}; ` }, { description: 'static methods with numeric or string names with varied spacing (#139)', input: ` class D { static .75(){} static"Static Method"(){} static "foo"(){} } `, output: ` var D = function D () {}; D[.75] = function (){}; D["Static Method"] = function (){}; D["foo"] = function (){}; ` }, { description: "don't shadow variables with function names (#166)", input: ` class X { foo() { return foo } bar() {} } `, output: ` var X = function X () {}; X.prototype.foo = function foo$1 () { return foo }; X.prototype.bar = function bar () {}; ` }, { description: "transpiles class with super class in arrow function (#150)", input: ` const f = (b) => class a extends b {}; `, output: ` var f = function (b) { return /*@__PURE__*/(function (b) { function a () { b.apply(this, arguments); }if ( b ) a.__proto__ = b; a.prototype = Object.create( b && b.prototype ); a.prototype.constructor = a; return a; }(b)); }; ` } // TODO more tests. e.g. getters and setters. // 'super.*' is not allowed before super() ]; buble-0.19.8/test/samples/computed-properties.js000066400000000000000000000104451350705536200217070ustar00rootroot00000000000000module.exports = [ { description: 'creates a computed property', input: ` var obj = { [a]: 1 };`, output: ` var obj = {}; obj[a] = 1;` }, { description: 'creates a computed property with a non-identifier expression', input: ` var obj = { [a()]: 1 };`, output: ` var obj = {}; obj[a()] = 1;` }, { description: 'creates a computed property at start of literal', input: ` var obj = { [a]: 1, b: 2 };`, output: ` var obj = {}; obj[a] = 1; obj.b = 2;` }, { description: 'creates a computed property at start of literal with method afterwards', input: ` var obj = { [a]: 1, b() {} };`, output: ` var obj = {}; obj[a] = 1; obj.b = function b() {};` }, { description: 'creates a computed property at start of literal with generator method afterwards when transpiling methods is disabled', options: { transforms: { conciseMethodProperty: false, generator: false } }, input: ` var obj = { [a]: 1, *b() {} };`, output: ` var obj = {}; obj[a] = 1; obj.b = function* () {};` }, { description: 'creates a computed property at end of literal', input: ` var obj = { a: 1, [b]: 2 };`, output: ` var obj = { a: 1 }; obj[b] = 2;` }, { description: 'creates a computed property in middle of literal', input: ` var obj = { a: 1, [b]: 2, c: 3 };`, output: ` var obj = { a: 1 }; obj[b] = 2; obj.c = 3;` }, { description: 'creates multiple computed properties', input: ` var obj = { [a]: 1, b: 2, [c]: 3, [d]: 4, e: 5, [f]: 6 };`, output: ` var obj = {}; obj[a] = 1; obj.b = 2; obj[c] = 3; obj[d] = 4; obj.e = 5; obj[f] = 6;` }, { description: 'creates computed property in complex expression', input: ` var a = 'foo', obj = { [a]: 'bar', x: 42 }, bar = obj.foo;`, output: ` var obj$1; var a = 'foo', obj = ( obj$1 = {}, obj$1[a] = 'bar', obj$1.x = 42, obj$1 ), bar = obj.foo;` }, { description: 'creates computed property in block with conflicts', input: ` var x; if ( true ) { let x = { [a]: 1 }; }`, output: ` var x; if ( true ) { var x$1 = {}; x$1[a] = 1; }` }, { description: 'closing parenthesis put in correct place (#73)', input: ` call({ [a]: 5 });`, output: ` var obj; call(( obj = {}, obj[a] = 5, obj ));` }, { description: 'creates a computed method (#78)', input: ` var obj = { [a] () { // code goes here } };`, output: ` var obj = {}; obj[a] = function () { // code goes here };` }, { description: 'creates a computed method with a non-identifier expression (#78)', input: ` var obj = { [a()] () { // code goes here } };`, output: ` var obj = {}; obj[a()] = function () { // code goes here };` }, { description: 'does not require space before parens of computed method (#82)', input: ` var obj = { [a]() { // code goes here } };`, output: ` var obj = {}; obj[a] = function () { // code goes here };` }, { description: 'supports computed shorthand function with object spread in body (#135)', options: { objectAssign: 'Object.assign' }, input: ` let a = { [foo] (x, y) { return { ...c }; }, }; `, output: ` var a = {}; a[foo] = function (x, y) { return Object.assign({}, c); }; ` }, { description: 'object literal with computed property within arrow expression (#126)', input: ` foo => bar({[x - y]: obj}); `, output: ` !function(foo) { var obj$1; return bar(( obj$1 = {}, obj$1[x - y] = obj, obj$1 )); }; ` }, { description: 'Supports nested computed properties (#51)', input: ` (function () { return { [key]: { [key]: val } } }) `, output: ` (function () { var obj, obj$1; return ( obj$1 = {}, obj$1[key] = ( obj = {}, obj[key] = val, obj ), obj$1 ) }) ` }, { description: 'Puts helper variables in correct scope', input: ` ((x) => {var obj = 2; console.log([{[x]: 1}, obj]);})(3); `, output: ` (function (x) { var obj$1; var obj = 2; console.log([( obj$1 = {}, obj$1[x] = 1, obj$1 ), obj]);})(3); ` } ]; buble-0.19.8/test/samples/default-parameters.js000066400000000000000000000044421350705536200214620ustar00rootroot00000000000000module.exports = [ { description: 'transpiles default parameters', input: ` function foo ( a = 1, b = 2 ) { console.log( a, b ); } var bar = function ( a = 1, b = 2 ) { console.log( a, b ); };`, output: ` function foo ( a, b ) { if ( a === void 0 ) a = 1; if ( b === void 0 ) b = 2; console.log( a, b ); } var bar = function ( a, b ) { if ( a === void 0 ) a = 1; if ( b === void 0 ) b = 2; console.log( a, b ); };` }, { description: 'transpiles default parameters in object pattern (#23)', input: ` function foo ({ a = 1 }) { console.log( a ); }`, output: ` function foo (ref) { var a = ref.a; if ( a === void 0 ) a = 1; console.log( a ); }` }, { description: 'transpiles multiple default parameters in object pattern', input: ` function foo ({ a = 1 }, { b = 2 }) { console.log( a, b ); } var bar = function ({ a = 1 }, { b = 2 }) { console.log( a, b ); };`, output: ` function foo (ref, ref$1) { var a = ref.a; if ( a === void 0 ) a = 1; var b = ref$1.b; if ( b === void 0 ) b = 2; console.log( a, b ); } var bar = function (ref, ref$1) { var a = ref.a; if ( a === void 0 ) a = 1; var b = ref$1.b; if ( b === void 0 ) b = 2; console.log( a, b ); };` }, { description: 'can be disabled with `transforms.defaultParameter: false`', options: { transforms: { defaultParameter: false } }, input: ` function foo ( a = 1, b = 2 ) { console.log( a, b ); } var bar = function ( a = 1, b = 2 ) { console.log( a, b ); };`, output: ` function foo ( a = 1, b = 2 ) { console.log( a, b ); } var bar = function ( a = 1, b = 2 ) { console.log( a, b ); };` }, { description: 'transpiles default arrow function parameters', input: ` function a(x, f = () => x) { console.log( f() ); }`, output: ` function a(x, f) { if ( f === void 0 ) f = function () { return x; }; console.log( f() ); }` }, { description: 'transpiles destructured default parameters (#43)', input: ` function a({ x = 1 } = {}) { console.log( x ); }`, output: ` function a(ref) { if ( ref === void 0 ) ref = {}; var x = ref.x; if ( x === void 0 ) x = 1; console.log( x ); }` } ]; buble-0.19.8/test/samples/destructuring.js000066400000000000000000000472121350705536200206010ustar00rootroot00000000000000module.exports = [ { description: 'destructures an identifier with an object pattern', input: ` var { x, y } = point;`, output: ` var x = point.x; var y = point.y;` }, { description: 'destructures a non-identifier with an object pattern', input: ` var { x, y } = getPoint();`, output: ` var ref = getPoint(); var x = ref.x; var y = ref.y;` }, { description: 'destructures a parameter with an object pattern', input: ` function pythag ( { x, y: z = 1 } ) { return Math.sqrt( x * x + z * z ); }`, output: ` function pythag ( ref ) { var x = ref.x; var z = ref.y; if ( z === void 0 ) z = 1; return Math.sqrt( x * x + z * z ); }` }, { description: 'uses different name than the property in a declaration', input: `var { foo: bar } = obj;`, output: `var bar = obj.foo;` }, { description: 'destructures an identifier with an array pattern', input: ` var [ x, y ] = point;`, output: ` var x = point[0]; var y = point[1];` }, { description: 'destructures an identifier with a sparse array pattern', input: ` var [ x, , z ] = point;`, output: ` var x = point[0]; var z = point[2];` }, { description: 'destructures a non-identifier with an array pattern', input: ` var [ x, y ] = getPoint();`, output: ` var ref = getPoint(); var x = ref[0]; var y = ref[1];` }, { description: 'destructures a parameter with an array pattern', input: ` function pythag ( [ x, z = 1 ] ) { return Math.sqrt( x * x + z * z ); }`, output: ` function pythag ( ref ) { var x = ref[0]; var z = ref[1]; if ( z === void 0 ) z = 1; return Math.sqrt( x * x + z * z ); }` }, { description: 'can be disabled in declarations with `transforms.destructuring === false`', options: { transforms: { destructuring: false } }, input: `var { x, y } = point;`, output: `var { x, y } = point;` }, { description: 'can be disabled in function parameters with `transforms.parameterDestructuring === false`', options: { transforms: { parameterDestructuring: false } }, input: `function foo ({ x, y }) {}`, output: `function foo ({ x, y }) {}` }, { description: 'does not destructure parameters intelligently (#53)', input: ` function drawRect ( { ctx, x1, y1, x2, y2 } ) { ctx.fillRect( x1, y1, x2 - x1, y2 - y1 ); } function scale ([ d0, d1 ], [ r0, r1 ]) { const m = ( r1 - r0 ) / ( d1 - d0 ); return function ( num ) { return r0 + ( num - d0 ) * m; } }`, output: ` function drawRect ( ref ) { var ctx = ref.ctx; var x1 = ref.x1; var y1 = ref.y1; var x2 = ref.x2; var y2 = ref.y2; ctx.fillRect( x1, y1, x2 - x1, y2 - y1 ); } function scale (ref, ref$1) { var d0 = ref[0]; var d1 = ref[1]; var r0 = ref$1[0]; var r1 = ref$1[1]; var m = ( r1 - r0 ) / ( d1 - d0 ); return function ( num ) { return r0 + ( num - d0 ) * m; } }` }, { description: 'does not destructure variable declarations intelligently (#53)', input: ` var { foo: bar, baz } = obj; console.log( bar ); console.log( baz ); console.log( baz );`, output: ` var bar = obj.foo; var baz = obj.baz; console.log( bar ); console.log( baz ); console.log( baz );` }, { description: 'destructures variables in the middle of a declaration', input: ` var a, { x, y } = getPoint(), b = x; console.log( x, y );`, output: ` var a; var ref = getPoint(); var x = ref.x; var y = ref.y; var b = x; console.log( x, y );` }, { description: 'destructuring a destructured parameter', input: ` function test ( { foo, bar } ) { const { x, y } = foo; }`, output: ` function test ( ref ) { var foo = ref.foo; var bar = ref.bar; var x = foo.x; var y = foo.y; }` }, { description: 'default value in destructured variable declaration (#37)', input: ` var { name: value, description = null } = obj; console.log( value, description );`, output: ` var value = obj.name; var description = obj.description; if ( description === void 0 ) description = null; console.log( value, description );` }, { description: 'default values in destructured object parameter with a default value (#37)', input: ` function foo ({ arg1 = 123, arg2 = 456 } = {}) { console.log( arg1, arg2 ); }`, output: ` function foo (ref) { if ( ref === void 0 ) ref = {}; var arg1 = ref.arg1; if ( arg1 === void 0 ) arg1 = 123; var arg2 = ref.arg2; if ( arg2 === void 0 ) arg2 = 456; console.log( arg1, arg2 ); }` }, { description: 'destructures not replacing reference from parent scope', input: ` function controller([element]) { const mapState = function ({ filter }) { console.log(element); }; }`, output: ` function controller(ref) { var element = ref[0]; var mapState = function (ref) { var filter = ref.filter; console.log(element); }; }` }, { description: 'deep matching with object patterns', input: ` var { a: { b: c }, d: { e: f, g: h = 1 } } = x;`, output: ` var c = x.a.b; var x_d = x.d; var f = x_d.e; var h = x_d.g; if ( h === void 0 ) h = 1;` }, { description: 'deep matching with string literals in object patterns', input: ` var { a, 'b-1': c } = x;`, output: ` var a = x.a; var c = x['b-1'];` }, { description: 'deep matching with object patterns and reference', input: ` var { a: { b: c }, d: { e: f, g: h } } = x();`, output: ` var ref = x(); var c = ref.a.b; var ref_d = ref.d; var f = ref_d.e; var h = ref_d.g;` }, { description: 'deep matching with array patterns', input: ` var [[[a]], [[b, c = 1]]] = x;`, output: ` var a = x[0][0][0]; var x_1_0 = x[1][0]; var b = x_1_0[0]; var c = x_1_0[1]; if ( c === void 0 ) c = 1;` }, { description: 'deep matching with sparse array', input: ` function foo ( [[[,x = 3] = []] = []] = [] ) { console.log( x ); }`, output: ` function foo ( ref ) { if ( ref === void 0 ) ref = []; var ref_0 = ref[0]; if ( ref_0 === void 0 ) ref_0 = []; var ref_0_0 = ref_0[0]; if ( ref_0_0 === void 0 ) ref_0_0 = []; var x = ref_0_0[1]; if ( x === void 0 ) x = 3; console.log( x ); }` }, { description: 'deep matching in parameters', input: ` function foo ({ a: { b: c }, d: { e: f, g: h } }) { console.log( c, f, h ); }`, output: ` function foo (ref) { var c = ref.a.b; var ref_d = ref.d; var f = ref_d.e; var h = ref_d.g; console.log( c, f, h ); }` }, { description: 'destructured object assignment with computed properties', input: ` let one, two, three, four; ({ [FirstProp]: one, [SecondProp]: two = 'Too', 3: three, Fore: four } = x); `, output: ` var assign; var one, two, three, four; ((assign = x, one = assign[FirstProp], two = assign[SecondProp], two = two === void 0 ? 'Too' : two, three = assign[3], four = assign.Fore)); ` }, { description: 'destructured object declaration with computed properties', input: ` var { [FirstProp]: one, [SecondProp]: two = 'Too', 3: three, Fore: four } = x; `, output: ` var one = x[FirstProp]; var two = x[SecondProp]; if ( two === void 0 ) two = 'Too'; var three = x[3]; var four = x.Fore; ` }, { description: 'destructured object declaration with computed properties and rest', input: ` var { [FirstProp]: one, [SecondProp]: two = 'Too', Fore: four, ...rest } = x; `, output: ` function objectWithoutProperties (obj, exclude) { var target = {}; for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k) && exclude.indexOf(k) === -1) target[k] = obj[k]; return target; } var one = x[FirstProp]; var two = x[SecondProp]; if ( two === void 0 ) two = 'Too'; var four = x.Fore; var rest$1 = objectWithoutProperties( x, [String(FirstProp), String(SecondProp), "Fore"] ); var rest = rest$1; ` }, { description: 'destructured object declaration with numeric properties and rest', input: ` var { 1: a, 2.: b, .3: c, 4e0: d, ...rest } = x; `, output: ` function objectWithoutProperties (obj, exclude) { var target = {}; for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k) && exclude.indexOf(k) === -1) target[k] = obj[k]; return target; } var a = x[1]; var b = x[2.]; var c = x[.3]; var d = x[4e0]; var rest$1 = objectWithoutProperties( x, ["1", "2", "0.3", "4"] ); var rest = rest$1; ` }, { description: 'destructured object with computed properties in parameters', input: ` function foo({ [FirstProp]: one, [SecondProp]: two = 'Too', 3: three, Fore: four } = x) { console.log(one, two, three, four); } `, output: ` function foo(ref) { if ( ref === void 0 ) ref = x; var one = ref[FirstProp]; var two = ref[SecondProp]; if ( two === void 0 ) two = 'Too'; var three = ref[3]; var four = ref.Fore; console.log(one, two, three, four); } ` }, { description: 'deep matching in parameters with computed properties', input: ` function foo ({ [a]: { [b]: c }, d: { 'e': f, [g]: h }, [i + j]: { [k + l]: m, n: o } }) { console.log( c, f, h, m, o ); }`, output: ` function foo (ref) { var c = ref[a][b]; var ref_d = ref.d; var f = ref_d['e']; var h = ref_d[g]; var ref_i_j = ref[i + j]; var m = ref_i_j[k + l]; var o = ref_i_j.n; console.log( c, f, h, m, o ); }` }, { description: 'array destructuring declaration with rest element', input: ` const [a, ...b] = [1, 2, 3, 4]; console.log(a, b); `, output: ` var ref = [1, 2, 3, 4]; var a = ref[0]; var b = ref.slice(1); console.log(a, b); ` }, { description: 'array destructuring declaration with complex rest element', input: ` const x = [1, 2, {r: 9}, 3], [a, ...[, {r: b, s: c = 4} ]] = x; console.log(a, b, c); `, output: ` var x = [1, 2, {r: 9}, 3]; var a = x[0]; var x_slice_1_1 = x.slice(1)[1]; var b = x_slice_1_1.r; var c = x_slice_1_1.s; if ( c === void 0 ) c = 4; console.log(a, b, c); ` }, { description: 'destructuring function parameters with array rest element', input: ` function foo([a, ...[, {r: b, s: c = 4} ]]) { console.log(a, b, c); } foo( [1, 2, {r: 9}, 3] ); `, output: ` function foo(ref) { var a = ref[0]; var ref_slice_1_1 = ref.slice(1)[1]; var b = ref_slice_1_1.r; var c = ref_slice_1_1.s; if ( c === void 0 ) c = 4; console.log(a, b, c); } foo( [1, 2, {r: 9}, 3] ); ` }, { description: 'destructuring array assignment with complex rest element', input: ` let x = [1, 2, {r: 9}, {s: ["table"]} ]; let a, b, c, d; ([a, ...[ , {r: b}, {r: c = "nothing", s: [d] = "nope"} ]] = x); console.log(a, b, c, d); `, output: ` var assign, assign_slice_1_, assign_slice_1_2, assign_slice_1_2_s; var x = [1, 2, {r: 9}, {s: ["table"]} ]; var a, b, c, d; ((assign = x, a = assign[0], assign_slice_1_ = assign.slice(1), b = assign_slice_1_[1].r, assign_slice_1_2 = assign_slice_1_[2], c = assign_slice_1_2.r, c = c === void 0 ? "nothing" : c, assign_slice_1_2_s = assign_slice_1_2.s, assign_slice_1_2_s = assign_slice_1_2_s === void 0 ? "nope" : assign_slice_1_2_s, d = assign_slice_1_2_s[0])); console.log(a, b, c, d); ` }, { description: 'destructuring array rest element within an object property', input: ` let foo = ({p: [x, ...y] = [6, 7], q: [...z] = [8]} = {}) => { console.log(x, y, z); }; foo({p: [1, 2, 3], q: [4, 5]}); foo({q: []} ); foo(); `, output: ` var foo = function (ref) { if ( ref === void 0 ) ref = {}; var ref_p = ref.p; if ( ref_p === void 0 ) ref_p = [6, 7]; var ref_p$1 = ref_p; var x = ref_p$1[0]; var y = ref_p$1.slice(1); var ref_q = ref.q; if ( ref_q === void 0 ) ref_q = [8]; var z = ref_q.slice(0); console.log(x, y, z); }; foo({p: [1, 2, 3], q: [4, 5]}); foo({q: []} ); foo(); ` }, { description: 'transpiles destructuring assignment of an array', input: ` [x, y] = [1, 2];`, output: ` var assign; (assign = [1, 2], x = assign[0], y = assign[1]);` }, { description: 'transpiles destructuring assignment of an array with a default value', input: ` [x = 4, y] = [1, 2];`, output: ` var assign; (assign = [1, 2], x = assign[0], x = x === void 0 ? 4 : x, y = assign[1]);` }, { description: 'transpiles nested destructuring assignment of an array', input: ` [[x], y] = [1, 2];`, output: ` var assign; (assign = [1, 2], x = assign[0][0], y = assign[1]);` }, { description: 'transpiles nested destructuring assignment of an array without evaluating a memberexpr twice', input: ` [[x, z], y] = [1, 2];`, output: ` var assign, assign_0; (assign = [1, 2], assign_0 = assign[0], x = assign_0[0], z = assign_0[1], y = assign[1]);` }, { description: 'transpiles nested destructuring assignment of an array with a default', input: ` [[x] = [], y] = [1, 2];`, output: ` var assign, assign_0; (assign = [1, 2], assign_0 = assign[0], assign_0 = assign_0 === void 0 ? [] : assign_0, x = assign_0[0], y = assign[1]);` }, { description: 'leaves member expression patterns intact', input: ` [x, y.z] = [1, 2];`, output: ` var assign; (assign = [1, 2], x = assign[0], y.z = assign[1]);` }, { description: 'only assigns to member expressions once', input: ` [x, y.z = 3] = [1, 2];`, output: ` var assign, assign_1; (assign = [1, 2], x = assign[0], assign_1 = assign[1], assign_1 = assign_1 === void 0 ? 3 : assign_1, y.z = assign_1);` }, { description: 'transpiles destructuring assignment of an object', input: ` ({x, y} = {x: 1});`, output: ` var assign; ((assign = {x: 1}, x = assign.x, y = assign.y));` }, { description: 'transpiles destructuring assignment of an object where key and pattern names differ', input: ` ({x, y: z} = {x: 1});`, output: ` var assign; ((assign = {x: 1}, x = assign.x, z = assign.y));` }, { description: 'transpiles nested destructuring assignment of an object', input: ` ({x, y: {z}} = {x: 1});`, output: ` var assign; ((assign = {x: 1}, x = assign.x, z = assign.y.z));` }, { description: 'transpiles destructuring assignment of an object with a default value', input: ` ({x, y = 4} = {x: 1});`, output: ` var assign; ((assign = {x: 1}, x = assign.x, y = assign.y, y = y === void 0 ? 4 : y));` }, { description: 'only evaluates a sub-object once', input: ` ({x, y: {z, q}} = {x: 1});`, output: ` var assign, assign_y; ((assign = {x: 1}, x = assign.x, assign_y = assign.y, z = assign_y.z, q = assign_y.q));` }, { description: "doesn't create an object temporary unless necessary", input: ` ({x, y: {z}} = {x: 1});`, output: ` var assign; ((assign = {x: 1}, x = assign.x, z = assign.y.z));` }, { description: 'lifts its variable declarations out of the expression', input: ` foo(); if ( bar([x, y] = [1, 2]) ) { baz(); }`, output: ` var assign; foo(); if ( bar((assign = [1, 2], x = assign[0], y = assign[1], assign)) ) { baz(); }` }, { description: 'puts its scratch variables in the parent scope', input: ` function foo() { [x, y] = [1, 2]; }`, output: ` function foo() { var assign; (assign = [1, 2], x = assign[0], y = assign[1]); }` }, { description: 'array destructuring default with template string (#145)', input: 'const [ foo = `${baz() - 4}` ] = bar;', output: `var foo = bar[0]; if ( foo === void 0 ) foo = "" + (baz() - 4);` }, { description: 'object destructuring default with template string (#145)', input: 'const { foo = `${baz() - 4}` } = bar;', output: `var foo = bar.foo; if ( foo === void 0 ) foo = "" + (baz() - 4);` }, { description: 'array destructuring with multiple defaults with hole', // FIXME: unnecessary parens needed around complex defaults due to buble bugs input: ` let [ a = \`A\${baz() - 4}\`, , /* hole */ c = (x => -x), d = ({ r: 5, [h()]: i }), ] = [ "ok" ]; `, output: ` var obj; var ref = [ "ok" ]; var a = ref[0]; if ( a === void 0 ) a = "A" + (baz() - 4); var c = ref[2]; if ( c === void 0 ) c = (function (x) { return -x; }); var d = ref[3]; if ( d === void 0 ) d = (( obj = { r: 5 }, obj[h()] = i, obj )); ` }, { description: 'object destructuring with multiple defaults', // FIXME: unnecessary parens needed around complex defaults due to buble bugs input: ` let { a = \`A\${baz() - 4}\`, c = (x => -x), d = ({ r: 5, [1 + 1]: 2, [h()]: i }), } = { b: 3 }; `, output: ` var obj; var ref = { b: 3 }; var a = ref.a; if ( a === void 0 ) a = "A" + (baz() - 4); var c = ref.c; if ( c === void 0 ) c = (function (x) { return -x; }); var d = ref.d; if ( d === void 0 ) d = (( obj = { r: 5 }, obj[1 + 1] = 2, obj[h()] = i, obj )); ` }, { description: 'destrucuring assignments requiring rvalues', input: ` class Point { set ( array ) { return [ this.x, this.y ] = array; } } let a, b, c = [ 1, 2, 3 ]; console.log( [ a, b ] = c ); `, output: ` var assign; var Point = function Point () {}; Point.prototype.set = function set ( array ) { var assign; return (assign = array, this.x = assign[0], this.y = assign[1], assign); }; var a, b, c = [ 1, 2, 3 ]; console.log( (assign = c, a = assign[0], b = assign[1], assign) ); ` }, { description: 'destrucuring assignments not requiring rvalues', input: ` class Point { set ( array ) { [ this.x, this.y ] = array; } } let a, b, c = [ 1, 2, 3 ]; [ a, b ] = c; `, output: ` var assign; var Point = function Point () {}; Point.prototype.set = function set ( array ) { var assign; (assign = array, this.x = assign[0], this.y = assign[1]); }; var a, b, c = [ 1, 2, 3 ]; (assign = c, a = assign[0], b = assign[1]); ` }, { description: 'destructures with computed property', input: ` const { a, b } = { ['a']: 1 }; `, output: ` var obj; var ref = ( obj = {}, obj['a'] = 1, obj ); var a = ref.a; var b = ref.b; ` }, { description: 'destructures within block scope', input: ` if (true) { let [[a, b]] = [[1, 2]]; } `, output: ` if (true) { var ref = [[1, 2]]; var ref_0 = ref[0]; var a = ref_0[0]; var b = ref_0[1]; } ` }, { description: 'destructures rewritten block scope variables', input: ` let x; if (maybe) { let x; ({ x } = { x: 3 }); [ x ] = [ 3 ]; }`, output: ` var assign, assign$1; var x; if (maybe) { var x$1; ((assign = { x: 3 }, x$1 = assign.x)); (assign$1 = [ 3 ], x$1 = assign$1[0]); }` }, { description: 'destructures try catch parameters', input: ` try {} catch ({message}) { }`, output: ` try {} catch (ref) { var message = ref.message; }` }, { description: 'destructures parameters with same name as function', input: ` const a = { options (options) { const { input } = options; } }`, output: ` var a = { options: function options (options$1) { var input = options$1.input; } }` }, { description: 'destructuring inside a brace-less if', input: ` if (from) [from, to] = [to, from]`, output: ` var assign; if (from) { (assign = [to, from], from = assign[0], to = assign[1]) }` }, { description: 'destructuring nested computed properties', options: { objectAssign: 'Object.assign' }, input: `var z1 = { [b]: { ...c, [d]: 'Hello, World!' } }`, output: ` var obj; var z1 = {}; z1[b] = Object.assign({}, c, ( obj = {}, obj[d] = 'Hello, World!', obj ))` } ]; buble-0.19.8/test/samples/dynamic-import.js000066400000000000000000000002761350705536200206320ustar00rootroot00000000000000module.exports = [ { description: 'support dynamic import', options: { transforms: { moduleImport: false } }, input: `import('./module.js')`, output: `import('./module.js')` } ]; buble-0.19.8/test/samples/exponentiation-operator.js000066400000000000000000000072111350705536200225670ustar00rootroot00000000000000module.exports = [ { description: 'transpiles an exponentiation operator', input: `x ** y`, output: `Math.pow( x, y )` }, { description: 'transpiles an exponentiation assignment to a simple reference', input: `x **= y`, output: `x = Math.pow( x, y )` }, { description: 'transpiles an exponentiation assignment to a simple parenthesized reference', input: `( x ) **= y`, output: `( x ) = Math.pow( x, y )` }, { description: 'transpiles an exponentiation assignment to a rewritten simple reference', input: ` let x = 1; if ( maybe ) { let x = 2; x **= y; }`, output: ` var x = 1; if ( maybe ) { var x$1 = 2; x$1 = Math.pow( x$1, y ); }` }, { description: 'transpiles an exponentiation assignment to a simple member expression', input: ` foo.bar **= y;`, output: ` foo.bar = Math.pow( foo.bar, y );` }, { description: 'transpiles an exponentiation assignment to a simple deep member expression', input: ` foo.bar.baz **= y;`, output: ` var object; object = foo.bar; object.baz = Math.pow( object.baz, y );` }, { description: 'transpiles an exponentiation assignment to a simple computed member expression', input: ` foo[ bar ] **= y;`, output: ` foo[ bar ] = Math.pow( foo[bar], y );` }, { description: 'transpiles an exponentiation assignment to a complex reference', input: ` foo[ bar() ] **= y;`, output: ` var property; property = bar(); foo[property] = Math.pow( foo[property], y );` }, { description: 'transpiles an exponentiation assignment to a contrivedly complex reference', input: ` foo[ bar() ][ baz() ] **= y;`, output: ` var property, object; object = foo[ bar() ]; property = baz(); object[property] = Math.pow( object[property], y );` }, { description: 'transpiles an exponentiation assignment to a contrivedly complex reference (that is not a top-level statement)', input: ` var baz = 1, lolwut = foo[ bar() ][ baz * 2 ] **= y;`, output: ` var property, object; var baz = 1, lolwut = ( object = foo[ bar() ], property = baz * 2, object[property] = Math.pow( object[property], y ) );` }, { description: 'transpiles an exponentiation assignment to a contrivedly complex reference with simple object (that is not a top-level statement)', input: ` var baz = 1, lolwut = foo[ bar() ] **= y;`, output: ` var property; var baz = 1, lolwut = ( property = bar(), foo[property] = Math.pow( foo[property], y ) );` }, { description: 'handles pathological bastard case', input: ` let i; if ( maybe ) { for ( let i = 1.1; i < 1e6; i **= i ) { setTimeout( function () { console.log( i ); }, i ); } }`, output: ` var i; if ( maybe ) { var loop = function ( i ) { setTimeout( function () { console.log( i ); }, i ); }; for ( var i$1 = 1.1; i$1 < 1e6; i$1 = Math.pow( i$1, i$1 ) ) loop( i$1 ); }` }, { description: 'handles assignment of exponentiation assignment to property', input: ` x=a.b**=2; `, output: ` x=a.b=Math.pow( a.b, 2 ); ` }, { description: 'handles assignment of exponentiation assignment to property with side effect', input: ` x=a[bar()]**=2; `, output: ` var property; x=( property = bar(), a[property]=Math.pow( a[property], 2 ) ); ` } /* TODO: Test currently errors out with: TypeError: Cannot read property 'property' of null { description: 'handles assignment of exponentiation assignment to property with side effect within a block-less if', input: ` if(y)x=a[foo()]**=2; `, output: ` ` }, */ ]; buble-0.19.8/test/samples/for-of.js000066400000000000000000000121261350705536200170630ustar00rootroot00000000000000module.exports = [ { description: 'disallows for-of statements', input: `for ( x of y ) {}`, error: /for-of statements is not fully supported/ }, { description: 'ignores for-of with `transforms.forOf === false`', options: { transforms: { forOf: false } }, input: `for ( x of y ) {}`, output: `for ( x of y ) {}` }, { description: 'transpiles for-of with array assumption with `transforms.dangerousForOf`', options: { transforms: { dangerousForOf: true } }, input: ` for ( let member of array ) { doSomething( member ); }`, output: ` for ( var i = 0, list = array; i < list.length; i += 1 ) { var member = list[i]; doSomething( member ); }` }, { description: 'transpiles for-of with expression', options: { transforms: { dangerousForOf: true } }, input: ` for ( let member of [ 'a', 'b', 'c' ] ) { doSomething( member ); }`, output: ` for ( var i = 0, list = [ 'a', 'b', 'c' ]; i < list.length; i += 1 ) { var member = list[i]; doSomething( member ); }` }, { description: 'transpiles for-of that needs to be rewritten as function', options: { transforms: { dangerousForOf: true } }, input: ` for ( let member of [ 'a', 'b', 'c' ] ) { setTimeout( function () { doSomething( member ); }); }`, output: ` var loop = function () { var member = list[i]; setTimeout( function () { doSomething( member ); }); }; for ( var i = 0, list = [ 'a', 'b', 'c' ]; i < list.length; i += 1 ) loop();` }, { description: 'transpiles body-less for-of', options: { transforms: { dangerousForOf: true } }, input: ` for ( let member of array ) console.log( member );`, output: ` for ( var i = 0, list = array; i < list.length; i += 1 ) { var member = list[i]; console.log( member ); }` }, { description: 'transpiles space-less for-of', options: { transforms: { dangerousForOf: true } }, input: ` for (const key of this.keys) { console.log(key); }`, output: ` for (var i = 0, list = this.keys; i < list.length; i += 1) { var key = list[i]; console.log(key); }` }, { description: 'handles continue in for-of', options: { transforms: { dangerousForOf: true } }, input: ` for ( let item of items ) { if ( item.foo ) continue; }`, output: ` for ( var i = 0, list = items; i < list.length; i += 1 ) { var item = list[i]; if ( item.foo ) { continue; } }` }, { description: 'handles this and arguments in for-of', options: { transforms: { dangerousForOf: true } }, input: ` for ( let item of items ) { console.log( this, arguments, item ); setTimeout( () => { console.log( item ); }); }`, output: ` var arguments$1 = arguments; var this$1 = this; var loop = function () { var item = list[i]; console.log( this$1, arguments$1, item ); setTimeout( function () { console.log( item ); }); }; for ( var i = 0, list = items; i < list.length; i += 1 ) loop();` }, { description: 'for-of with empty block (#80)', options: { transforms: { dangerousForOf: true } }, input: ` for ( let x of y ) {}`, output: ` ` }, { description: 'for-of with empty block and var (#80)', options: { transforms: { dangerousForOf: true } }, input: ` for ( var x of y ) {}`, output: ` var x;` }, { description: 'return from for-of loop rewritten as function', options: { transforms: { dangerousForOf: true } }, input: ` function foo () { for ( let x of y ) { setTimeout( function () { console.log( x ); }); if ( x > 10 ) return; } }`, output: ` function foo () { var loop = function () { var x = list[i]; setTimeout( function () { console.log( x ); }); if ( x > 10 ) { return {}; } }; for ( var i = 0, list = y; i < list.length; i += 1 ) { var returned = loop(); if ( returned ) return returned.v; } }` }, { description: 'allows destructured variable declaration (#95)', options: { transforms: { dangerousForOf: true } }, input: ` for (var {x, y} of [{x: 1, y: 2}]) { console.log(x, y); }`, output: ` for (var i = 0, list = [{x: 1, y: 2}]; i < list.length; i += 1) { var ref = list[i]; var x = ref.x; var y = ref.y; console.log(x, y); }` }, { description: 'destructures assignment in forOf loop', options: { transforms: { dangerousForOf: true } }, input: ` var x, y; for ({x, y} of [{x: 1, y: 2}]) { console.log(x, y); } `, output: ` var x, y; for (var i = 0, list = [{x: 1, y: 2}]; i < list.length; i += 1) { var ref = list[i]; x = ref.x; y = ref.y; console.log(x, y); } ` }, { description: 'destructures assignment in forOf loop with array pattern', options: { transforms: { dangerousForOf: true } }, input: ` var x, y; for ([x, y] of [[1, 2]]) { console.log(x, y); } `, output: ` var x, y; for (var i = 0, list = [[1, 2]]; i < list.length; i += 1) { var ref = list[i]; x = ref[0]; y = ref[1]; console.log(x, y); } ` } ]; buble-0.19.8/test/samples/generators.js000066400000000000000000000033531350705536200200460ustar00rootroot00000000000000module.exports = [ { description: 'disallows generator function declarations', input: ` function* foo () { }`, error: /Transforming generators is not implemented/ }, { description: 'disallows generator function expressions', input: ` var fn = function* foo () { }`, error: /Transforming generators is not implemented/ }, { description: 'disallows generator functions as object literal methods', input: ` var obj = { *foo () { } };`, error: /Transforming generators is not implemented/ }, { description: 'disallows generator functions as class methods', input: ` class Foo { *foo () { } }`, error: /Transforming generators is not implemented/ }, { description: 'ignores generator function declarations with `transforms.generator: false`', options: { transforms: { generator: false } }, input: `function* foo () {}`, output: `function* foo () {}` }, { description: 'ignores generator function expressions with `transforms.generator: false`', options: { transforms: { generator: false } }, input: `var foo = function* foo () {}`, output: `var foo = function* foo () {}` }, { description: 'ignores generator function methods with `transforms.generator: false`', options: { transforms: { generator: false } }, input: `var obj = { *foo () {} }`, output: `var obj = { foo: function* foo () {} }` }, { description: 'ignores generator function class methods with `transforms.generator: false`', options: { transforms: { generator: false } }, input: ` class Foo { *foo () { // code goes here } }`, output: ` var Foo = function Foo () {}; Foo.prototype.foo = function* foo () { // code goes here };` } ]; buble-0.19.8/test/samples/get-set.js000066400000000000000000000031521350705536200172420ustar00rootroot00000000000000module.exports = [ { description: 'is disabled by default for classes', input: `class X { get x() {} }`, output: `var X = function X () {}; var prototypeAccessors = { x: { configurable: true } }; prototypeAccessors.x.get = function () {}; Object.defineProperties( X.prototype, prototypeAccessors );`, }, { description: 'is disabled by default for objects', input: `X = { get x() {} }`, output: `X = { get x() {} }`, }, { description: 'can be explicitly enabled for classes', options: { transforms: { getterSetter: true } }, input: `class X { get x() {} }`, error: /getters and setters is not implemented. Use `transforms: { getterSetter: false }` to skip transformation and disable this error. \(2:3\)/ }, { description: 'can be explicitly enabled for objects', options: { transforms: { getterSetter: true } }, input: `X = { get x() {} }`, error: /getters and setters is not implemented. Use `transforms: { getterSetter: false }` to skip transformation and disable this error. \(2:3\)/ }, { description: 'are automatically enabled for ie8 for classes', options: { target: { ie: 8 } }, input: `class X { get x() {} }`, error: /getters and setters is not implemented. Use `transforms: { getterSetter: false }` to skip transformation and disable this error. \(2:3\)/ }, { description: 'are automatically enabled for ie8 for objects', options: { target: { ie: 8 } }, input: `X = { get x() {} }`, error: /getters and setters is not implemented. Use `transforms: { getterSetter: false }` to skip transformation and disable this error. \(2:3\)/ }, ] buble-0.19.8/test/samples/json-superset.js000066400000000000000000000004471350705536200205170ustar00rootroot00000000000000module.exports = [ { description: 'transpiles U+2028 LINE SEPARATOR', input: `const x = "a\u2028b\u1010"`, output: `var x = "a\\u2028b\u1010"` }, { description: 'transpiles U+2029 PARAGRAPH SEPARATOR', input: `const x = "a\u2029b\u1010"`, output: `var x = "a\\u2029b\u1010"` } ] buble-0.19.8/test/samples/jsx.js000066400000000000000000000172231350705536200165020ustar00rootroot00000000000000module.exports = [ { description: 'transpiles self-closing JSX tag', input: `var img = ;`, output: `var img = React.createElement( 'img', { src: 'foo.gif' });` }, { description: 'transpiles non-self-closing JSX tag', input: `var div =
;`, output: `var div = React.createElement( 'div', { className: 'foo' });` }, { description: 'transpiles non-self-closing JSX tag without attributes', input: `var div =
;`, output: `var div = React.createElement( 'div', null );` }, { description: 'transpiles nested JSX tags', input: ` var div = (
);`, output: ` var div = ( React.createElement( 'div', { className: 'foo' }, React.createElement( 'img', { src: 'foo.gif' }), React.createElement( 'img', { src: 'bar.gif' }) ) );` }, { description: 'transpiles JSX tag with expression attributes', input: `var img = ;`, output: `var img = React.createElement( 'img', { src: src });` }, { description: 'transpiles JSX tag with expression children', input: ` var div = (
{ images.map( src => ) }
);`, output: ` var div = ( React.createElement( 'div', null, images.map( function (src) { return React.createElement( 'img', { src: src }); } ) ) );` }, { description: 'transpiles JSX component', input: `var element = ;`, output: `var element = React.createElement( Hello, { name: name });` }, { description: 'transpiles empty JSX expression block', input: `var element = {};`, output: `var element = React.createElement( Foo, null );` }, { description: 'transpiles empty JSX expression block with comment', input: `var element = {/* comment */};`, output: `var element = React.createElement( Foo, null/* comment */ );` }, { description: 'transpiles JSX component without attributes', input: `var element = ;`, output: `var element = React.createElement( Hello, null );` }, { description: 'transpiles JSX component without attributes with children', input: `var element = hello;`, output: `var element = React.createElement( Hello, null, "hello" );` }, { description: 'transpiles namespaced JSX component', input: `var element = ;`, output: `var element = React.createElement( Foo.Bar, { name: name });` }, { description: 'supports pragmas', options: { jsx: 'NotReact.createElement' }, input: `var img = ;`, output: `var img = NotReact.createElement( 'img', { src: 'foo.gif' });` }, { description: 'stringifies text children', input: `

Hello {name}!

`, output: `React.createElement( 'h1', null, "Hello ", name, "!" )` }, { description: 'handles whitespace and quotes appropriately', input: `

Hello {name} !

`, output: ` React.createElement( 'h1', null, "Hello ", name, "!" )` }, { description: 'handles single-line whitespace and quotes appropriately', input: `

Hello {name} – and goodbye!

`, output: ` React.createElement( 'h1', null, "Hello ", name, " – and goodbye!" )` }, { description: 'handles single quotes in text children', input: `

Hello {name} !${' '} It's nice to meet you

`, output: ` React.createElement( 'h1', null, "Hello ", name, "! It's nice to meet you" )` }, { description: 'transpiles tag with data attribute', input: `var element =
;`, output: `var element = React.createElement( 'div', { 'data-name': name });` }, { description: 'transpiles JSX tag without value', input: `var div =
;`, output: `var div = React.createElement( 'div', { contentEditable: true });` }, { description: 'transpiles JSX fragments', input: `var divs = <>
;`, output: `var divs = React.createElement( React.Fragment, null, React.createElement( 'div', { contentEditable: true }), React.createElement( 'div', null ) );` }, { description: 'transpiles one JSX spread attributes', input: `var element =
;`, output: `var element = React.createElement( 'div', props);` }, { description: 'disallow mixed JSX spread attributes ending in spread', input: `var element =
;`, error: /Mixed JSX attributes ending in spread requires specified objectAssign option with 'Object\.assign' or polyfill helper\./ }, { description: 'transpiles mixed JSX spread attributes ending in spread', options: { objectAssign: 'Object.assign' }, input: `var element =
;`, output: `var element = React.createElement( 'div', Object.assign({}, { a: 1 }, props, stuff));` }, { description: 'transpiles mixed JSX spread attributes ending in spread with custom Object.assign', options: { objectAssign: 'angular.extend' }, input: `var element =
;`, output: `var element = React.createElement( 'div', angular.extend({}, { a: 1 }, props, stuff));` }, { description: 'transpiles mixed JSX spread attributes ending in other values', options: { objectAssign: 'Object.assign' }, input: `var element =
;`, output: `var element = React.createElement( 'div', Object.assign({}, { a: 1 }, props, { b: 2, c: 3 }, stuff, { more: things }));` }, { description: 'transpiles spread expressions (#64)', input: `
`, output: `React.createElement( 'div', this.props)` }, { description: 'handles whitespace between elements on same line (#65)', input: `

Hello {name}!

`, output: ` React.createElement( Foo, null, " ", React.createElement( 'h1', null, "Hello ", name, "!" ), " " )` }, { description: 'fix Object.assign regression in JSXOpeningElement (#163)', options: { objectAssign: 'Object.assign' }, input: ` `, output: ` React.createElement( Thing, Object.assign({}, { two: "This no longer fails" }, props)) ` }, { description: 'fix no space between JSXOpeningElement attributes (#178)', input: `
`, output: ` React.createElement( 'div', { style: {color:'#000000'}, className: 'content' }) ` }, { description: 'supports /* @jsx customPragma */ directives (#195)', input: ` /* @jsx customPragma */ var div =
Hello
`, output: ` /* @jsx customPragma */ var div = customPragma( 'div', null, "Hello" ) ` }, { description: 'ignores subsequent /* @jsx customPragma */ directives (#195)', input: ` /* @jsx customPragma */ /* @jsx customPragmaWannabe */ var div =
Hello
`, output: ` /* @jsx customPragma */ /* @jsx customPragmaWannabe */ var div = customPragma( 'div', null, "Hello" ) ` }, { description: 'handles dash-cased value-less props', input: ` `, output: ` React.createElement( Thing, { 'data-foo': true }) ` }, { description: 'handles non-breaking white-space entities', input: `
1   
`, output: ` React.createElement( 'div', null, React.createElement( 'a', null, "1" ), "   ") ` }, { description: 'transpiles entities', input: `
1< 
`, output: ` React.createElement( 'div', null, React.createElement( 'a', null, "1<" ), " ") ` } ]; buble-0.19.8/test/samples/loops.js000066400000000000000000000407021350705536200170300ustar00rootroot00000000000000module.exports = [ { description: 'transpiles block scoping inside loops with function bodies', input: ` function log ( square ) { console.log( square ); } for ( let i = 0; i < 10; i += 1 ) { const square = i * i; setTimeout( function () { log( square ); }, i * 100 ); }`, output: ` function log ( square ) { console.log( square ); } var loop = function ( i ) { var square = i * i; setTimeout( function () { log( square ); }, i * 100 ); }; for ( var i = 0; i < 10; i += 1 ) loop( i );` }, { description: 'transpiles block scoping inside while loops with function bodies', input: ` function log ( square ) { console.log( square ); } while ( i-- ) { const square = i * i; setTimeout( function () { log( square ); }, i * 100 ); }`, output: ` function log ( square ) { console.log( square ); } var loop = function () { var square = i * i; setTimeout( function () { log( square ); }, i * 100 ); }; while ( i-- ) loop();` }, { description: 'transpiles block scoping inside do-while loops with function bodies', input: ` function log ( square ) { console.log( square ); } do { const square = i * i; setTimeout( function () { log( square ); }, i * 100 ); } while ( i-- );`, output: ` function log ( square ) { console.log( square ); } var loop = function () { var square = i * i; setTimeout( function () { log( square ); }, i * 100 ); }; do { loop(); } while ( i-- );` }, { description: 'transpiles block-less for loops with block-scoped declarations inside function body', input: ` for ( let i = 0; i < 10; i += 1 ) setTimeout( () => console.log( i ), i * 100 );`, output: ` var loop = function ( i ) { setTimeout( function () { return console.log( i ); }, i * 100 ); }; for ( var i = 0; i < 10; i += 1 ) loop( i );` }, { description: 'transpiles block scoping inside loops without function bodies', input: ` for ( let i = 0; i < 10; i += 1 ) { const square = i * i; console.log( square ); }`, output: ` for ( var i = 0; i < 10; i += 1 ) { var square = i * i; console.log( square ); }` }, { description: 'transpiles block-less for loops without block-scoped declarations inside function body', input: ` for ( let i = 0; i < 10; i += 1 ) console.log( i );`, output: ` for ( var i = 0; i < 10; i += 1 ) { console.log( i ); }` }, { description: 'preserves correct `this` and `arguments` inside block scoped loop (#10)', input: ` for ( let i = 0; i < 10; i += 1 ) { console.log( this, arguments, i ); setTimeout( function () { console.log( this, arguments, i ); }, i * 100 ); }`, output: ` var arguments$1 = arguments; var this$1 = this; var loop = function ( i ) { console.log( this$1, arguments$1, i ); setTimeout( function () { console.log( this, arguments, i ); }, i * 100 ); }; for ( var i = 0; i < 10; i += 1 ) loop( i );` }, { description: 'maintains value of for loop variables between iterations (#11)', input: ` var fns = []; for ( let i = 0; i < 10; i += 1 ) { fns.push(function () { return i; }); i += 1; }`, output: ` var fns = []; var loop = function ( i$1 ) { fns.push(function () { return i$1; }); i$1 += 1; i = i$1; }; for ( var i = 0; i < 10; i += 1 ) loop( i );` }, { description: 'maintains value of for loop variables between iterations, with conflict (#11)', input: ` var i = 'conflicting'; var fns = []; for ( let i = 0; i < 10; i += 1 ) { fns.push(function () { return i; }); i += 1; }`, output: ` var i = 'conflicting'; var fns = []; var loop = function ( i$2 ) { fns.push(function () { return i$2; }); i$2 += 1; i$1 = i$2; }; for ( var i$1 = 0; i$1 < 10; i$1 += 1 ) loop( i$1 );` }, { description: 'loop variables with UpdateExpresssions between iterations (#150)', input: ` var fns = []; for ( let i = 0, j = 3; i < 10; i += 1 ) { fns.push(function () { return i; }); ++i; j--; }`, output: ` var fns = []; var loop = function ( i$1, j$1 ) { fns.push(function () { return i$1; }); ++i$1; j$1--; i = i$1; j = j$1; }; for ( var i = 0, j = 3; i < 10; i += 1 ) loop( i, j );` }, { description: 'loop variables with UpdateExpresssions between iterations, with conflict (#150)', input: ` var i = 'conflicting'; var fns = []; for ( let i = 0; i < 10; i += 1 ) { fns.push(function () { return i; }); i++; }`, output: ` var i = 'conflicting'; var fns = []; var loop = function ( i$2 ) { fns.push(function () { return i$2; }); i$2++; i$1 = i$2; }; for ( var i$1 = 0; i$1 < 10; i$1 += 1 ) loop( i$1 );` }, { description: 'handles break and continue inside block-scoped loops (#12)', input: ` function foo () { for ( let i = 0; i < 10; i += 1 ) { if ( i % 2 ) continue; if ( i > 5 ) break; if ( i === 'potato' ) return 'huh?'; setTimeout( () => console.log( i ) ); } }`, output: ` function foo () { var loop = function ( i ) { if ( i % 2 ) { return; } if ( i > 5 ) { return 'break'; } if ( i === 'potato' ) { return { v: 'huh?' }; } setTimeout( function () { return console.log( i ); } ); }; for ( var i = 0; i < 10; i += 1 ) { var returned = loop( i ); if ( returned === 'break' ) break; if ( returned ) return returned.v; } }` }, { description: 'rewrites for-in loops as functions as necessary', input: ` for ( let foo in bar ) { setTimeout( function () { console.log( bar[ foo ] ) } ); }`, output: ` var loop = function ( foo ) { setTimeout( function () { console.log( bar[ foo ] ) } ); }; for ( var foo in bar ) loop( foo );` }, { description: 'allows breaking from for-in loops', input: ` for ( let foo in bar ) { if ( foo === 'baz' ) break; setTimeout( function () { console.log( bar[ foo ] ) } ); }`, output: ` var loop = function ( foo ) { if ( foo === 'baz' ) { return 'break'; } setTimeout( function () { console.log( bar[ foo ] ) } ); }; for ( var foo in bar ) { var returned = loop( foo ); if ( returned === 'break' ) break; }` }, { description: 'transpiles block-less for-in statements', input: `for ( let foo in bar ) baz( foo );`, output: `for ( var foo in bar ) { baz( foo ); }` }, { description: 'transpiles block-less for-in statements as functions', input: ` for ( let foo in bar ) setTimeout( function () { log( foo ) } );`, output: ` var loop = function ( foo ) { setTimeout( function () { log( foo ) } ); }; for ( var foo in bar ) loop( foo );` }, { description: 'does not incorrectly rename variables declared in for loop head', input: ` for ( let foo = 0; foo < 10; foo += 1 ) { foo += 1; console.log( foo ); }`, output: ` for ( var foo = 0; foo < 10; foo += 1 ) { foo += 1; console.log( foo ); }` }, { description: 'does not rewrite as function if `transforms.letConst === false`', options: { transforms: { letConst: false } }, input: ` for ( let i = 0; i < 10; i += 1 ) { setTimeout( function () { log( i ); }, i * 100 ); }`, output: ` for ( let i = 0; i < 10; i += 1 ) { setTimeout( function () { log( i ); }, i * 100 ); }` }, { description: 'calls synthetic loop function with correct argument', input: ` let i = 999; for ( let i = 0; i < 10; i += 1 ) { setTimeout( () => console.log( i ) ); }`, output: ` var i = 999; var loop = function ( i ) { setTimeout( function () { return console.log( i ); } ); }; for ( var i$1 = 0; i$1 < 10; i$1 += 1 ) loop( i$1 );` }, { description: 'handles body-less do-while loops (#27)', input: `do foo(); while (bar)`, output: `do { foo(); } while (bar)` }, { description: 'returns without a value from loop', input: ` function foo ( x ) { for ( let i = 0; i < x; i += 1 ) { setTimeout( () => { console.log( i ); }); if ( x > 5 ) return; } }`, output: ` function foo ( x ) { var loop = function ( i ) { setTimeout( function () { console.log( i ); }); if ( x > 5 ) { return {}; } }; for ( var i = 0; i < x; i += 1 ) { var returned = loop( i ); if ( returned ) return returned.v; } }` }, { description: 'supports two compiled loops in one function', input: ` function foo ( x ) { for ( let i = 0; i < x; i += 1 ) { setTimeout( () => { console.log( i ); }); if ( x > 5 ) return; } for ( let i = 0; i < x; i += 1 ) { setTimeout( () => { console.log( i ); }); if ( x > 5 ) return; } }`, output: ` function foo ( x ) { var loop = function ( i ) { setTimeout( function () { console.log( i ); }); if ( x > 5 ) { return {}; } }; for ( var i = 0; i < x; i += 1 ) { var returned = loop( i ); if ( returned ) return returned.v; } var loop$1 = function ( i ) { setTimeout( function () { console.log( i ); }); if ( x > 5 ) { return {}; } }; for ( var i$1 = 0; i$1 < x; i$1 += 1 ) { var returned$1 = loop$1( i$1 ); if ( returned$1 ) return returned$1.v; } }` }, { description: 'destructures variable declaration in for loop head', input: ` var range = { start: 10, end: 20 }; for ( var { start: i, end } = range; i < end; i += 1 ) { console.log( i ); }`, output: ` var range = { start: 10, end: 20 }; for ( var i = range.start, end = range.end; i < end; i += 1 ) { console.log( i ); }` }, { description: 'complex destructuring in variable declaration in for loop head', input: ` var range = function () { return { start: 10, end: 20 }; } for ( var { start: i, end = 100 } = range(); i < end; i += 1 ) { console.log( i ); }`, output: ` var range = function () { return { start: 10, end: 20 }; } for ( var ref = range(), i = ref.start, end = ref.end, end = end === void 0 ? 100 : end; i < end; i += 1 ) { console.log( i ); }` }, { description: 'nested destructuring in variable declaration in for loop head', input: ` for ( var { start: { a, b } } = range(); i < end; i += 1 ) { console.log( i ); }`, output: ` for ( var ref = range(), ref_start = ref.start, a = ref_start.a, b = ref_start.b; i < end; i += 1 ) { console.log( i ); }` }, { description: 'nested array destructuring in variable declaration in for loop head', input: ` for ( var [[x, z], y] = [1, 2]; i < end; i += 1 ) { console.log( i ); }`, output: ` for ( var ref = [1, 2], ref_0 = ref[0], x = ref_0[0], z = ref_0[1], y = ref[1]; i < end; i += 1 ) { console.log( i ); }` }, { description: 'array destructuring with default value in variable declaration in for loop head', input: ` for ( var [x, y = 4, z] = [1, 2, 3]; i < end; i += 1 ) { console.log( i ); }`, output: ` for ( var ref = [1, 2, 3], x = ref[0], y = ref[1], y = y === void 0 ? 4 : y, z = ref[2]; i < end; i += 1 ) { console.log( i ); }` }, { description: 'object destructuring with default value in variable declaration in for loop head', input: ` for ( var {x, y = 4, z} = {}; i < end; i += 1 ) { console.log( i ); }`, output: ` for ( var ref = {}, x = ref.x, y = ref.y, y = y === void 0 ? 4 : y, z = ref.z; i < end; i += 1 ) { console.log( i ); }` }, { description: 'arrow functions in block-less for loops in a block-less if/else chain (#110)', input: ` if (x) for (let i = 0; i < a.length; ++i) (() => { console.log(a[i]); })(); else if (y) for (let i = 0; i < b.length; ++i) (() => { console.log(b[i]); })(); else for (let i = 0; i < c.length; ++i) (() => { console.log(c[i]); })(); `, // the indentation is not ideal, but the code is correct... output: ` if (x) { var loop = function ( i ) { (function () { console.log(a[i]); })(); }; for (var i = 0; i < a.length; ++i) loop( i ); } else if (y) { var loop$1 = function ( i ) { (function () { console.log(b[i]); })(); }; for (var i$1 = 0; i$1 < b.length; ++i$1) loop$1( i$1 ); } else { var loop$2 = function ( i ) { (function () { console.log(c[i]); })(); }; for (var i$2 = 0; i$2 < c.length; ++i$2) loop$2( i$2 ); } ` }, { description: 'always initialises block-scoped variable in loop (#124)', input: ` for (let i = 0; i < 10; i++) { let something; if (i % 2) something = true; console.log(something); }`, output: ` for (var i = 0; i < 10; i++) { var something = (void 0); if (i % 2) { something = true; } console.log(something); }` }, { description: 'always initialises block-scoped variable in for-of loop (#125)', options: { transforms: { dangerousForOf: true } }, input: ` for (let a = 0; a < 10; a++) { let j = 1, k; for (let b of c) { let x, y = 2 f(b, j, k, x, y) } } `, output: ` for (var a = 0; a < 10; a++) { var j = 1, k = (void 0); for (var i = 0, list = c; i < list.length; i += 1) { var b = list[i]; var x = (void 0), y = 2 f(b, j, k, x, y) } } ` }, { description: 'always initialises block-scoped variable in simple for-of loop (#125)', options: { transforms: { dangerousForOf: true } }, input: ` for (let b of c) { let x, y = 2, z; f(b, x++, y++, z++) } `, output: ` for (var i = 0, list = c; i < list.length; i += 1) { var b = list[i]; var x = (void 0), y = 2, z = (void 0); f(b, x++, y++, z++) } ` }, { description: 'always initialises block-scoped variable in for-in loop', input: ` for (let k in obj) { var r = 1, s, t; let x, y = 2, z; f(k, r++, s++, t++, x++, y++, z++) } `, output: ` for (var k in obj) { var r = 1, s, t; var x = (void 0), y = 2, z = (void 0); f(k, r++, s++, t++, x++, y++, z++) } ` }, { description: 'use alias for this in right side of nested for-in loop declaration (#142)', input: ` let arr = []; class Foo { constructor () { this.foo = { a: 1, b: 2 }; } do() { for ( let move = 0; move < 5; ++move ) { for ( let id in this.foo ) arr.push( id ); ( () => { arr.push( move ); } )( move ); } console.log( arr.join( ' ' ) ); } } new Foo().do(); `, output: ` var arr = []; var Foo = function Foo () { this.foo = { a: 1, b: 2 }; }; Foo.prototype.do = function do$1 () { var this$1 = this; var loop = function ( move ) { for ( var id in this$1.foo ) { arr.push( id ); } ( function () { arr.push( move ); } )( move ); }; for ( var move = 0; move < 5; ++move ) loop( move ); console.log( arr.join( ' ' ) ); }; new Foo().do(); ` }, { description: 'use alias for this in right side of nested for-of loop declaration (#142)', options: { transforms: { dangerousForOf: true } }, input: ` let arr = []; class Foo { constructor () { this.foo = [ 9, 7 ]; } do() { for ( let move = 0; move < 5; ++move ) { for ( let id of this.foo ) arr.push( id ); ( () => { arr.push( move ); } )( move ); } console.log( arr.join( ' ' ) ); } } new Foo().do(); `, output: ` var arr = []; var Foo = function Foo () { this.foo = [ 9, 7 ]; }; Foo.prototype.do = function do$1 () { var this$1 = this; var loop = function ( move ) { for ( var i = 0, list = this$1.foo; i < list.length; i += 1 ) { var id = list[i]; arr.push( id ); } ( function () { arr.push( move ); } )( move ); }; for ( var move = 0; move < 5; ++move ) loop( move ); console.log( arr.join( ' ' ) ); }; new Foo().do(); ` }, { description: 'transpiles destructuring in for-in loop heads', input: `for (var [a, b] in []) {}`, output: `for (var ref in []) {var a = ref[0]; var b = ref[1]; }` }, { description: 'transpiles destructuring in for-in loop heads', input: ` for ([a, b = "_"] in []) f(a, b)`, output: ` for (var ref in []) { var a = ref[0]; var b = ref[1]; if ( b === void 0 ) b = "_"; f(a, b) }` } ]; buble-0.19.8/test/samples/misc.js000066400000000000000000000060261350705536200166300ustar00rootroot00000000000000module.exports = [ { description: 'handles empty return', input: ` function foo () { return; }`, output: ` function foo () { return; }` }, { description: 'allows break statement inside switch', input: ` switch ( foo ) { case bar: console.log( 'bar' ); break; default: console.log( 'default' ); }`, output: ` switch ( foo ) { case bar: console.log( 'bar' ); break; default: console.log( 'default' ); }` }, { description: 'double var is okay', input: ` function foo () { var x = 1; var x = 2; }`, output: ` function foo () { var x = 1; var x = 2; }` }, { description: 'var followed by let is not okay', input: ` function foo () { var x = 1; let x = 2; }`, error: /Identifier 'x' has already been declared/ }, { description: 'let followed by var is not okay', input: ` function foo () { let x = 1; var x = 2; }`, error: /Identifier 'x' has already been declared/ }, { description: 'does not get confused about keys of Literal node', input: ` console.log( null ); console.log( 'some string' ); console.log( null );`, output: ` console.log( null ); console.log( 'some string' ); console.log( null );` }, { description: 'handles sparse arrays (#62)', input: `var a = [ , 1 ], b = [ 1, ], c = [ 1, , 2 ], d = [ 1, , , ];`, output: `var a = [ , 1 ], b = [ 1 ], c = [ 1, , 2 ], d = [ 1, , , ];` }, { description: 'Safari/WebKit bug workaround: parameter shadowing function expression name (#154)', input: ` "use strict"; // necessary to trigger WebKit bug class Foo { bar (bar) { return bar; } static baz (foo, bar, baz) { return foo * baz - baz * bar; } } var a = class Bar { b (a, b, c) { return a * b - c * b + b$1 - b$2; } }; var b = class { b (a, b, c) { return a * b - c * b; } }; var c = { b (a, b, c) { return a * b - c * b; } }; var d = function foo(foo) { return foo; }; // FunctionDeclaration is not subject to the WebKit bug function bar(bar) { return bar; } `, output: ` "use strict"; // necessary to trigger WebKit bug var Foo = function Foo () {}; Foo.prototype.bar = function bar (bar$1) { return bar$1; }; Foo.baz = function baz (foo, bar, baz$1) { return foo * baz$1 - baz$1 * bar; }; var a = /*@__PURE__*/(function () { function Bar () {} Bar.prototype.b = function b (a, b$3, c) { return a * b$3 - c * b$3 + b$1 - b$2; }; return Bar; }()); var b = /*@__PURE__*/(function () { function b () {} b.prototype.b = function b (a, b$1, c) { return a * b$1 - c * b$1; }; return b; }()); var c = { b: function b (a, b$1, c) { return a * b$1 - c * b$1; } }; var d = function foo(foo$1) { return foo$1; }; // FunctionDeclaration is not subject to the WebKit bug function bar(bar) { return bar; } ` } ]; buble-0.19.8/test/samples/modules.js000066400000000000000000000030011350705536200173330ustar00rootroot00000000000000module.exports = [ { description: 'disallows import statement', input: `import 'foo';`, error: /import is not implemented/ }, { description: 'disallows export statement', input: `var foo; export { foo };`, error: /export is not implemented/ }, { description: 'imports are ignored with `transforms.moduleImport === false`', options: { transforms: { moduleImport: false } }, input: `import 'foo';`, output: `import 'foo';` }, { description: 'exports are ignored with `transforms.moduleExport === false`', options: { transforms: { moduleExport: false } }, input: `var foo; export { foo };`, output: `var foo; export { foo };` }, { description: 'imports and exports are ignored with `transforms.modules === false`', options: { transforms: { modules: false } }, input: `import 'foo'; var foo; export { foo };`, output: `import 'foo'; var foo; export { foo };` }, { description: 'Supports anonymous functions as default export', options: { transforms: { modules: false } }, input: `export default function () {}`, output: `export default function () {}` }, { description: 'Supports anonymous classes as default export', options: { transforms: { modules: false } }, input: ` export default class { constructor() { foo() } a() { bar() } } `, output: ` var defaultExport = function defaultExport() { foo() }; defaultExport.prototype.a = function a () { bar() }; export default defaultExport; ` } ]; buble-0.19.8/test/samples/object-properties-no-named-function-expressions.js000066400000000000000000000050171350705536200272330ustar00rootroot00000000000000module.exports = [ { description: 'transpiles shorthand properties', options: { namedFunctionExpressions: false }, input: `obj = { x, y }`, output: `obj = { x: x, y: y }` }, { description: 'transpiles shorthand methods', options: { namedFunctionExpressions: false }, input: ` obj = { foo () { return 42; } }`, output: ` obj = { foo: function () { return 42; } }` }, { description: 'transpiles shorthand methods with quoted names (#82)', options: { namedFunctionExpressions: false }, input: ` obj = { 'foo-bar' () { return 42; } }`, output: ` obj = { 'foo-bar': function () { return 42; } }` }, { description: 'transpiles shorthand methods with reserved names (!68)', options: { namedFunctionExpressions: false }, input: ` obj = { catch () { return 42; } }`, output: ` obj = { catch: function () { return 42; } }` }, { description: 'transpiles shorthand methods with numeric or string names (#139)', options: { namedFunctionExpressions: false }, input: ` obj = { 0() {}, 0b101() {}, 80() {}, .12e3() {}, 0o753() {}, 12e34() {}, 0xFFFF() {}, "a string"() {}, "var"() {}, }`, output: ` obj = { 0: function() {}, 5: function() {}, 80: function() {}, .12e3: function() {}, 491: function() {}, 12e34: function() {}, 0xFFFF: function() {}, "a string": function() {}, "var": function() {}, }` }, { description: 'shorthand properties can be disabled with `transforms.conciseMethodProperty === false`', options: { namedFunctionExpressions: false, transforms: { conciseMethodProperty: false } }, input: `var obj = { x, y, z () {} }`, output: `var obj = { x, y, z () {} }` }, { description: 'computed properties can be disabled with `transforms.computedProperty === false`', options: { namedFunctionExpressions: false, transforms: { computedProperty: false } }, input: `var obj = { [x]: 'x' }`, output: `var obj = { [x]: 'x' }` }, { description: 'transpiles computed properties without spacing (#117)', options: { namedFunctionExpressions: false }, input: ` if (1) console.log(JSON.stringify({['com'+'puted']:1,['foo']:2})); else console.log(JSON.stringify({['bar']:3})); `, output: ` var obj, obj$1; if (1) { console.log(JSON.stringify(( obj = {}, obj['com'+'puted'] = 1, obj['foo'] = 2, obj ))); } else { console.log(JSON.stringify(( obj$1 = {}, obj$1['bar'] = 3, obj$1 ))); } ` } ]; buble-0.19.8/test/samples/object-properties.js000066400000000000000000000061631350705536200213370ustar00rootroot00000000000000module.exports = [ { description: 'transpiles shorthand properties', input: `obj = { x, y }`, output: `obj = { x: x, y: y }` }, { description: 'transpiles shorthand methods', input: ` obj = { foo () { return 42; } }`, output: ` obj = { foo: function foo () { return 42; } }` }, { description: 'transpiles shorthand methods with quoted names (#82)', input: ` obj = { 'foo-bar' () { return 42; } }`, output: ` obj = { 'foo-bar': function foo_bar () { return 42; } }` }, { description: 'transpiles shorthand methods with reserved names (!68)', input: ` obj = { catch () { return 42; } }`, output: ` obj = { catch: function catch$1 () { return 42; } }` }, { description: 'transpiles shorthand methods with numeric or string names (#139)', input: ` obj = { 0() {}, 0b101() {}, 80() {}, .12e3() {}, 0o753() {}, 12e34() {}, 0xFFFF() {}, "a string"() {}, "var"() {}, }`, output: ` obj = { 0: function () {}, 5: function () {}, 80: function () {}, .12e3: function () {}, 491: function () {}, 12e34: function () {}, 0xFFFF: function () {}, "a string": function astring() {}, "var": function var$1() {}, }` }, { description: 'shorthand properties can be disabled with `transforms.conciseMethodProperty === false`', options: { transforms: { conciseMethodProperty: false } }, input: `var obj = { x, y, z () {} }`, output: `var obj = { x, y, z () {} }` }, { description: 'computed properties can be disabled with `transforms.computedProperty === false`', options: { transforms: { computedProperty: false } }, input: `var obj = { [x]: 'x' }`, output: `var obj = { [x]: 'x' }` }, { description: 'transpiles computed properties without spacing (#117)', input: ` if (1) console.log(JSON.stringify({['com'+'puted']:1,['foo']:2})); else console.log(JSON.stringify({['bar']:3})); `, output: ` var obj, obj$1; if (1) { console.log(JSON.stringify(( obj = {}, obj['com'+'puted'] = 1, obj['foo'] = 2, obj ))); } else { console.log(JSON.stringify(( obj$1 = {}, obj$1['bar'] = 3, obj$1 ))); } ` }, { description: 'transpiles string-keyed properties after computed properties', input: ` fn({['computed']:1, 'some-var':2, a: 3}); `, output: ` var obj; fn(( obj = {}, obj['computed'] = 1, obj['some-var'] = 2, obj.a = 3, obj )); ` }, { description: 'transpiles string-keyed properties after computed properties with excessive whitespaces after the key', input: ` fn({['computed']: 1, 'some-var':2, 'some-var-2': 3, 'some-var-3' :4, 'some-var-4' : 5, a: 6}); `, output: ` var obj; fn(( obj = {}, obj['computed'] = 1, obj['some-var'] = 2, obj['some-var-2'] = 3, obj['some-var-3'] = 4, obj['some-var-4'] = 5, obj.a = 6, obj )); `, }, { description: 'avoids shadowing free variables with method names (#166)', input: ` let x = { foo() { return foo }, bar() {} } `, output: ` var x = { foo: function foo$1() { return foo }, bar: function bar() {} } ` } ]; buble-0.19.8/test/samples/object-rest-spread.js000066400000000000000000000266701350705536200214010ustar00rootroot00000000000000module.exports = [ { description: 'disallows object spread operator', input: 'var obj = {...a};', error: /Object spread operator requires specified objectAssign option with 'Object\.assign' or polyfill helper\./ }, { description: 'transpiles object spread with one object', options: { objectAssign: 'Object.assign' }, input: `var obj = {...a};`, output: `var obj = Object.assign({}, a);` }, { description: 'transpiles object spread with two objects', options: { objectAssign: 'Object.assign' }, input: `var obj = {...a, ...b};`, output: `var obj = Object.assign({}, a, b);` }, { description: 'transpiles object spread with regular keys in between', options: { objectAssign: 'Object.assign' }, input: `var obj = { ...a, b: 1, c: 2 };`, output: `var obj = Object.assign({}, a, {b: 1, c: 2});` }, { description: 'transpiles object spread mixed', options: { objectAssign: 'Object.assign' }, input: `var obj = { ...a, b: 1, ...d, e};`, output: `var obj = Object.assign({}, a, {b: 1}, d, {e: e});` }, { description: 'transpiles objects with spread with computed property (#144)', options: { objectAssign: 'Object.assign' }, input: ` var a0 = { [ x ] : true , ... y }; var a1 = { [ w ] : 0 , [ x ] : true , ... y }; var a2 = { v, [ w ] : 0, [ x ] : true, ... y }; var a3 = { [ w ] : 0, [ x ] : true }; var a4 = { [ w ] : 0 , [ x ] : true , y }; var a5 = { k : 9 , [ x ] : true, ... y }; var a6 = { ... y, [ x ] : true }; var a7 = { ... y, [ w ] : 0, [ x ] : true }; var a8 = { k : 9, ... y, [ x ] : true }; var a9 = { [ x ] : true , [ y ] : false , [ z ] : 9 }; var a10 = { [ x ] : true, ...y, p, ...q }; var a11 = { x, [c] : 9 , y }; var a12 = { ...b, [c]:3, d:4 }; `, output: ` var obj, obj$1, obj$2, obj$3, obj$4, obj$5, obj$6, obj$7, obj$8; var a0 = Object.assign(( obj = {}, obj[ x ] = true, obj ), y); var a1 = Object.assign(( obj$1 = {}, obj$1[ w ] = 0, obj$1[ x ] = true, obj$1 ), y); var a2 = Object.assign(( obj$2 = { v: v }, obj$2[ w ] = 0, obj$2[ x ] = true, obj$2 ), y); var a3 = {}; a3[ w ] = 0; a3[ x ] = true; var a4 = {}; a4[ w ] = 0; a4[ x ] = true; a4.y = y; var a5 = Object.assign(( obj$3 = { k : 9 }, obj$3[ x ] = true, obj$3 ), y); var a6 = Object.assign({}, y, ( obj$4 = {}, obj$4[ x ] = true, obj$4 )); var a7 = Object.assign({}, y, ( obj$5 = {}, obj$5[ w ] = 0, obj$5[ x ] = true, obj$5 )); var a8 = Object.assign({ k : 9 }, y, ( obj$6 = {}, obj$6[ x ] = true, obj$6 )); var a9 = {}; a9[ x ] = true; a9[ y ] = false; a9[ z ] = 9; var a10 = Object.assign(( obj$7 = {}, obj$7[ x ] = true, obj$7 ), y, {p: p}, q); var a11 = { x: x }; a11[c] = 9; a11.y = y; var a12 = Object.assign({}, b, ( obj$8 = {}, obj$8[c] = 3, obj$8 ), {d:4}); ` }, { description: 'doesn\'t transpile objects with spread with computed property if disabled', options: { objectAssign: 'Object.assign', transforms: { objectRestSpread: false, computedProperty: false, conciseMethodProperty: false } }, input: ` var a0 = { [ x ] : true , ... y }; var a1 = { [ w ] : 0 , [ x ] : true , ... y }; var a2 = { v, [ w ] : 0, [ x ] : true, ... y }; var a3 = { [ w ] : 0, [ x ] : true }; var a4 = { [ w ] : 0 , [ x ] : true , y }; var a5 = { k : 9 , [ x ] : true, ... y }; var a6 = { ... y, [ x ] : true }; var a7 = { ... y, [ w ] : 0, [ x ] : true }; var a8 = { k : 9, ... y, [ x ] : true }; var a9 = { [ x ] : true , [ y ] : false , [ z ] : 9 }; var a10 = { [ x ] : true, ...y, p, ...q }; var a11 = { x, [c] : 9 , y }; var a12 = { ...b, [c]:3, d:4 }; `, output: ` var a0 = { [ x ] : true , ... y }; var a1 = { [ w ] : 0 , [ x ] : true , ... y }; var a2 = { v, [ w ] : 0, [ x ] : true, ... y }; var a3 = { [ w ] : 0, [ x ] : true }; var a4 = { [ w ] : 0 , [ x ] : true , y }; var a5 = { k : 9 , [ x ] : true, ... y }; var a6 = { ... y, [ x ] : true }; var a7 = { ... y, [ w ] : 0, [ x ] : true }; var a8 = { k : 9, ... y, [ x ] : true }; var a9 = { [ x ] : true , [ y ] : false , [ z ] : 9 }; var a10 = { [ x ] : true, ...y, p, ...q }; var a11 = { x, [c] : 9 , y }; var a12 = { ...b, [c]:3, d:4 }; ` }, { description: 'supports transpiling spread properties if computed properties shouldn\'t be transpiled', options: { objectAssign: 'Object.assign', transforms: { computedProperty: false, conciseMethodProperty: false } }, input: ` var a0 = { [ x ] : true , ... y }; `, output: ` var a0 = Object.assign({}, {[ x ] : true} , y); `, }, { description: 'supports transpiling computed properties if spread properties shouldn\'t be transpiled', options: { objectAssign: 'Object.assign', transforms: { objectRestSpread: false, conciseMethodProperty: false } }, input: ` var a0 = { [ x ] : true , ... y }; `, output: ` var obj; var a0 = Object.assign(( obj = {}, obj[ x ] = true, obj ), y); `, }, { description: 'transpiles inline objects with spread with computed property (#144)', options: { objectAssign: 'Object.assign' }, input: ` f0( { [ x ] : true , ... y } ); f1( { [ w ] : 0 , [ x ] : true , ... y } ); f2( { v, [ w ] : 0, [ x ] : true, ... y } ); f3( { [ w ] : 0, [ x ] : true } ); f4( { [ w ] : 0 , [ x ] : true , y } ); f5( { k : 9 , [ x ] : true, ... y } ); f6( { ... y, [ x ] : true } ); f7( { ... y, [ w ] : 0, [ x ] : true } ); f8( { k : 9, ... y, [ x ] : true } ); f9( { [ x ] : true , [ y ] : false , [ z ] : 9 } ); f10( { [ x ] : true, ...y, p, ...q } ); f11( { x, [c] : 9 , y } ); f12({ ...b, [c]:3, d:4 }); `, output: ` var obj, obj$1, obj$2, obj$3, obj$4, obj$5, obj$6, obj$7, obj$8, obj$9, obj$10, obj$11, obj$12; f0( Object.assign(( obj = {}, obj[ x ] = true, obj ), y) ); f1( Object.assign(( obj$1 = {}, obj$1[ w ] = 0, obj$1[ x ] = true, obj$1 ), y) ); f2( Object.assign(( obj$2 = { v: v }, obj$2[ w ] = 0, obj$2[ x ] = true, obj$2 ), y) ); f3( ( obj$3 = {}, obj$3[ w ] = 0, obj$3[ x ] = true, obj$3 ) ); f4( ( obj$4 = {}, obj$4[ w ] = 0, obj$4[ x ] = true, obj$4.y = y, obj$4 ) ); f5( Object.assign(( obj$5 = { k : 9 }, obj$5[ x ] = true, obj$5 ), y) ); f6( Object.assign({}, y, ( obj$6 = {}, obj$6[ x ] = true, obj$6 )) ); f7( Object.assign({}, y, ( obj$7 = {}, obj$7[ w ] = 0, obj$7[ x ] = true, obj$7 )) ); f8( Object.assign({ k : 9 }, y, ( obj$8 = {}, obj$8[ x ] = true, obj$8 )) ); f9( ( obj$9 = {}, obj$9[ x ] = true, obj$9[ y ] = false, obj$9[ z ] = 9, obj$9 ) ); f10( Object.assign(( obj$10 = {}, obj$10[ x ] = true, obj$10 ), y, {p: p}, q) ); f11( ( obj$11 = { x: x }, obj$11[c] = 9, obj$11.y = y, obj$11 ) ); f12(Object.assign({}, b, ( obj$12 = {}, obj$12[c] = 3, obj$12 ), {d:4})); ` }, { description: 'transpiles object spread nested', options: { objectAssign: 'Object.assign' }, input: `var obj = { ...a, b: 1, dd: {...d, f: 1}, e};`, output: `var obj = Object.assign({}, a, {b: 1, dd: Object.assign({}, d, {f: 1}), e: e});` }, { description: 'transpiles object spread deeply nested', options: { objectAssign: 'Object.assign' }, input: `const c = { ...a, b: 1, dd: {...d, f: 1, gg: {h, ...g, ii: {...i}}}, e};`, output: `var c = Object.assign({}, a, {b: 1, dd: Object.assign({}, d, {f: 1, gg: Object.assign({}, {h: h}, g, {ii: Object.assign({}, i)})}), e: e});` }, { description: 'transpiles object spread with custom Object.assign', options: { objectAssign: 'angular.extend' }, input: `var obj = { ...a, b: 1, dd: {...d, f: 1}, e};`, output: `var obj = angular.extend({}, a, {b: 1, dd: angular.extend({}, d, {f: 1}), e: e});` }, { description: 'transpiles rest properties', input: `var {a, ...b} = c`, output: `function objectWithoutProperties (obj, exclude) { var target = {}; for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k) && exclude.indexOf(k) === -1) target[k] = obj[k]; return target; } var a = c.a; var rest = objectWithoutProperties( c, ["a"] ); var b = rest;` }, { description: 'transpiles rest properties in assignments', input: `({a, ...b} = c);`, output: `function objectWithoutProperties (obj, exclude) { var target = {}; for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k) && exclude.indexOf(k) === -1) target[k] = obj[k]; return target; } var assign, rest; ((assign = c, a = assign.a, rest = objectWithoutProperties( assign, ["a"] ), b = rest));` }, { description: 'transpiles rest properties in arguments', input: ` "use strict"; function objectWithoutProperties({x, ...y}) {}`, output: ` "use strict"; function objectWithoutProperties$1 (obj, exclude) { var target = {}; for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k) && exclude.indexOf(k) === -1) target[k] = obj[k]; return target; } function objectWithoutProperties(ref) { var x = ref.x; var rest = objectWithoutProperties$1( ref, ["x"] ); var y = rest; }` }, { description: 'transpiles rest properties in arrow function arguments', input: `(({x, ...y}) => {})`, output: `function objectWithoutProperties (obj, exclude) { var target = {}; for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k) && exclude.indexOf(k) === -1) target[k] = obj[k]; return target; } (function (ref) { var x = ref.x; var rest = objectWithoutProperties( ref, ["x"] ); var y = rest; })` }, { description: 'transpiles rest properties in for loop heads', input: `for( var {a, ...b} = c;; ) {}`, output: `function objectWithoutProperties (obj, exclude) { var target = {}; for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k) && exclude.indexOf(k) === -1) target[k] = obj[k]; return target; } for( var a = c.a, rest = objectWithoutProperties( c, ["a"] ), b = rest;; ) {}` }, { description: 'transpiles trivial rest properties in for loop heads', input: `for( var {...b} = c;; ) {}`, output: `function objectWithoutProperties (obj, exclude) { var target = {}; for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k) && exclude.indexOf(k) === -1) target[k] = obj[k]; return target; } for( var rest = objectWithoutProperties( c, [] ), b = rest;; ) {}` }, { description: 'inlines object spread with one object', input: `var obj = {...{a: 1}};`, output: `var obj = {a: 1};` }, { description: 'inlines object spread with two objects', input: `var obj = {...{a: 1}, ...{b: 2}};`, output: `var obj = {a: 1, b: 2};` }, { description: 'inlines object spread with regular keys in between', input: `var obj = { ...{a: 1}, b: 2, c: 3 };`, output: `var obj = { a: 1, b: 2, c: 3 };` }, { description: 'inlines object spread mixed', input: `var obj = { ...{a: 1}, b: 2, ...{c: 3}, e};`, output: `var obj = { a: 1, b: 2, c: 3, e: e};` }, { description: 'inlines object spread very mixed', options: { objectAssign: 'Object.assign' }, input: `var obj = { ...{a: 1}, b: 2, ...c, e};`, output: `var obj = Object.assign({}, {a: 1, b: 2}, c, {e: e});` }, { description: 'inlines object spread without extraneous trailing commas', options: { objectAssign: 'Object.assign' }, input: ` var obj = { ...{a: 1,}, b: 2, ...{c: 3,}, ...d, e, ...{f: 6,},}; obj = { a: 1, b: 2, }; obj = { a: 1, ...{b: 2} }; obj = { a: 1, ...{b: 2,} }; obj = { a: 1, ...{b: 2}, }; obj = { a: 1, ...{b: 2,}, }; `, output: ` var obj = Object.assign({}, {a: 1, b: 2, c: 3}, d, {e: e, f: 6}); obj = { a: 1, b: 2, }; obj = { a: 1, b: 2 }; obj = { a: 1, b: 2 }; obj = { a: 1, b: 2, }; obj = { a: 1, b: 2, }; ` } ]; buble-0.19.8/test/samples/regex.js000066400000000000000000000016051350705536200170050ustar00rootroot00000000000000module.exports = [ { description: 'transpiles regex with unicode flag', input: `var regex = /foo.bar/u;`, output: `var regex = /foo(?:[\\0-\\t\\x0B\\f\\x0E-\\u2027\\u202A-\\uD7FF\\uE000-\\uFFFF]|[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]|[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDFFF])bar/;` }, { description: 'disallows sticky flag in regex literals', input: `var regex = /x/y;`, error: /Transforming the regular expression sticky flag is not implemented/ }, { description: 'u flag is ignored with `transforms.unicodeRegExp === false`', options: { transforms: { unicodeRegExp: false } }, input: `var regex = /x/u;`, output: `var regex = /x/u;` }, { description: 'y flag is ignored with `transforms.stickyRegExp === false`', options: { transforms: { stickyRegExp: false } }, input: `var regex = /x/y;`, output: `var regex = /x/y;` } ]; buble-0.19.8/test/samples/reserved-properties.js000066400000000000000000000013531350705536200217040ustar00rootroot00000000000000module.exports = [ { description: 'rewrites member expressions that are reserved words', options: { transforms: { reservedProperties: true } }, input: `foo.then + foo.catch`, output: `foo.then + foo['catch']` }, { description: 'rewrites object literal properties that are reserved words', options: { transforms: { reservedProperties: true } }, input: `obj = { then: 1, catch: 2 }`, output: `obj = { then: 1, 'catch': 2 }` }, { description: 'does not rewrite member expressions by default', input: `foo.then + foo.catch`, output: `foo.then + foo.catch` }, { description: 'does not rewrite object literal properties by default', input: `obj = { then: 1, catch: 2 }`, output: `obj = { then: 1, catch: 2 }` } ]; buble-0.19.8/test/samples/rest-parameters.js000066400000000000000000000017011350705536200210060ustar00rootroot00000000000000module.exports = [ { description: 'transpiles solo rest parameters', input: ` function foo ( ...theRest ) { console.log( theRest ); }`, output: ` function foo () { var theRest = [], len = arguments.length; while ( len-- ) theRest[ len ] = arguments[ len ]; console.log( theRest ); }` }, { description: 'transpiles rest parameters following other parameters', input: ` function foo ( a, b, c, ...theRest ) { console.log( theRest ); }`, output: ` function foo ( a, b, c ) { var theRest = [], len = arguments.length - 3; while ( len-- > 0 ) theRest[ len ] = arguments[ len + 3 ]; console.log( theRest ); }` }, { description: 'can be disabled with `transforms.spreadRest === false`', options: { transforms: { spreadRest: false } }, input: ` function foo ( ...list ) { // code goes here }`, output: ` function foo ( ...list ) { // code goes here }` } ]; buble-0.19.8/test/samples/spread-operator.js000066400000000000000000000470631350705536200210120ustar00rootroot00000000000000module.exports = [ { description: 'transpiles a lone spread operator', input: `var clone = [ ...arr ]`, output: `var clone = [].concat( arr )` }, { description: 'transpiles a spread element in array with trailing comma', input: `var clone = [ ...arr, ];`, output: `var clone = [].concat( arr );` }, { description: 'transpiles a spread operator with other values', input: `var list = [ a, b, ...remainder ]`, output: `var list = [ a, b ].concat( remainder )` // TODO preserve whitespace conventions }, { description: 'transpiles a lone spread operator in a method call', input: `var max = Math.max( ...values );`, output: `var max = Math.max.apply( Math, values );` }, { description: 'transpiles a spread operator in a method call with other arguments', input: `var max = Math.max( 0, ...values );`, output: `var max = Math.max.apply( Math, [ 0 ].concat( values ) );` }, { description: 'transpiles a spread operator in a method call of an expression', input: ` ( foo || bar ).baz( ...values );`, output: ` var ref; (ref = ( foo || bar )).baz.apply( ref, values );` }, { description: 'transpiles a spread operator in a method call of this (#100)', input: ` function a( args ) { return this.go( ...args ); }`, output: ` function a( args ) { var ref; return (ref = this).go.apply( ref, args ); }` }, { description: 'transpiles a spread operator in a call in an arrow function using this (#115)', input: ` function foo(...args) { return Domain.run(() => { return this.go(...args); }); } function bar(args) { return Domain.run(() => { return this.go(...args); }); } function baz() { return Domain.run(() => { return this.go(...arguments); }); } `, output: ` function foo() { var this$1 = this; var args = [], len = arguments.length; while ( len-- ) args[ len ] = arguments[ len ]; return Domain.run(function () { var ref; return (ref = this$1).go.apply(ref, args); }); } function bar(args) { var this$1 = this; return Domain.run(function () { var ref; return (ref = this$1).go.apply(ref, args); }); } function baz() { var arguments$1 = arguments; var this$1 = this; return Domain.run(function () { var ref; return (ref = this$1).go.apply(ref, arguments$1); }); } ` }, { description: 'transpiles a spread operator in a new call in an arrow function using this', input: ` function foo(...args) { return Domain.run(() => { return new this.Test(...args); }); } function bar(args) { return Domain.run(() => { return new this.Test(...args); }); } function baz() { return Domain.run(() => { return new this.Test(...arguments); }); } `, output: ` function foo() { var this$1 = this; var args = [], len = arguments.length; while ( len-- ) args[ len ] = arguments[ len ]; return Domain.run(function () { return new (Function.prototype.bind.apply( this$1.Test, [ null ].concat( args) )); }); } function bar(args) { var this$1 = this; return Domain.run(function () { return new (Function.prototype.bind.apply( this$1.Test, [ null ].concat( args) )); }); } function baz() { var arguments$1 = arguments; var this$1 = this; var i = arguments.length, argsArray = Array(i); while ( i-- ) argsArray[i] = arguments[i]; return Domain.run(function () { return new (Function.prototype.bind.apply( this$1.Test, [ null ].concat( argsArray) )); }); } ` }, { description: 'transpiles a spread operator in an expression method call within an if', input: ` var result; if ( ref ) result = expr().baz( ...values ); process( result );`, output: ` var ref$1; var result; if ( ref ) { result = (ref$1 = expr()).baz.apply( ref$1, values ); } process( result );` }, { description: 'transpiles spread operators in expression method calls within a function', input: ` function foo() { stuff(); if ( ref ) return expr().baz( ...values ); return (up || down).bar( ...values ); }`, output: ` function foo() { var ref$1, ref$2; stuff(); if ( ref ) { return (ref$1 = expr()).baz.apply( ref$1, values ); } return (ref$2 = (up || down)).bar.apply( ref$2, values ); }` }, { description: 'transpiles spread operators in a complex nested scenario', input: ` function ref() { stuff(); if ( ref$1 ) return expr().baz( a, ...values, (up || down).bar( c, ...values, d ) ); return other(); }`, output: ` function ref() { var ref, ref$2; stuff(); if ( ref$1 ) { return (ref = expr()).baz.apply( ref, [ a ].concat( values, [(ref$2 = (up || down)).bar.apply( ref$2, [ c ].concat( values, [d] ) )] ) ); } return other(); }` }, { description: 'transpiles spread operators in issue #92', input: ` var adder = { add(...numbers) { return numbers.reduce((a, b) => a + b, 0) }, prepare() { return this.add.bind(this, ...arguments) } }`, output: ` var adder = { add: function add() { var numbers = [], len = arguments.length; while ( len-- ) numbers[ len ] = arguments[ len ]; return numbers.reduce(function (a, b) { return a + b; }, 0) }, prepare: function prepare() { var i = arguments.length, argsArray = Array(i); while ( i-- ) argsArray[i] = arguments[i]; var ref; return (ref = this.add).bind.apply(ref, [ this ].concat( argsArray )) } }` }, { description: 'transpiles spread operators with template literals (issue #99)', input: 'console.log( `%s ${label}:`, `${color}`, ...args );', output: 'console.log.apply( console, [ ("%s " + label + ":"), ("" + color) ].concat( args ) );' }, { description: 'transpiles a lone spread operator in a function call', input: `log( ...values );`, output: `log.apply( void 0, values );` }, { description: 'transpiles a spread operator in a function call with other arguments', input: `sprintf( str, ...values );`, output: `sprintf.apply( void 0, [ str ].concat( values ) );` }, { description: 'transpiles a spread operator in an expression call', input: `( foo || bar )( ...values );`, output: `( foo || bar ).apply( void 0, values );` }, { description: 'can be disabled in array expressions `transforms.spreadRest: false`', options: { transforms: { spreadRest: false } }, input: `var chars = [ ...string ]`, output: `var chars = [ ...string ]` }, { description: 'can be disabled in call expressions with `transforms.spreadRest: false`', options: { transforms: { spreadRest: false } }, input: `var max = Math.max( ...values );`, output: `var max = Math.max( ...values );` }, { description: 'transpiles multiple spread operators in an array', input: `var arr = [ ...a, ...b, ...c ];`, output: `var arr = a.concat( b, c );` }, { description: 'transpiles multiple spread operators in an array with trailing comma', input: `var arr = [ ...a, ...b, ...c, ];`, output: `var arr = a.concat( b, c );` }, { description: 'transpiles mixture of spread and non-spread elements', input: `var arr = [ ...a, b, ...c, d ];`, output: `var arr = a.concat( [b], c, [d] );` }, { description: 'transpiles mixture of spread and non-spread elements in array with trailing comma', input: `var arr = [ ...a, b, ...c, d, ];`, output: `var arr = a.concat( [b], c, [d] );` }, { description: 'transpiles ...arguments', input: ` function foo () { var args = [ ...arguments ]; return args; }`, output: ` function foo () { var i = arguments.length, argsArray = Array(i); while ( i-- ) argsArray[i] = arguments[i]; var args = [].concat( argsArray ); return args; }` // TODO if this is the only use of argsArray, don't bother concating }, { description: 'transpiles ...arguments in array with trailing comma', input: ` function foo () { var args = [ ...arguments, ]; return args; }`, output: ` function foo () { var i = arguments.length, argsArray = Array(i); while ( i-- ) argsArray[i] = arguments[i]; var args = [].concat( argsArray ); return args; }` // TODO if this is the only use of argsArray, don't bother concating }, { description: 'transpiles ...arguments in middle of array', input: ` function foo () { var arr = [ a, ...arguments, b ]; return arr; }`, output: ` function foo () { var i = arguments.length, argsArray = Array(i); while ( i-- ) argsArray[i] = arguments[i]; var arr = [ a ].concat( argsArray, [b] ); return arr; }` }, { description: 'transpiles multiple spread operators in function call', input: `var max = Math.max( ...theseValues, ...thoseValues );`, output: `var max = Math.max.apply( Math, theseValues.concat( thoseValues ) );` }, { description: 'transpiles mixture of spread and non-spread operators in function call', input: `var max = Math.max( ...a, b, ...c, d );`, output: `var max = Math.max.apply( Math, a.concat( [b], c, [d] ) );` }, { description: 'transpiles ...arguments in function call', input: ` function foo () { return Math.max( ...arguments ); }`, output: ` function foo () { return Math.max.apply( Math, arguments ); }` }, { description: 'transpiles ...arguments in middle of function call', input: ` function foo () { return Math.max( a, ...arguments, b ); }`, output: ` function foo () { var i = arguments.length, argsArray = Array(i); while ( i-- ) argsArray[i] = arguments[i]; return Math.max.apply( Math, [ a ].concat( argsArray, [b] ) ); }` }, { description: 'transpiles new with spread args', input: ` function Test() { this.a = [...arguments]; console.log(JSON.stringify(this.a)); } var obj = { Test }; var a = [1, 2]; var b = [3, 4]; var c = [7, 8]; new Test(...a); new obj.Test(...a); new (null || obj).Test(...a); new Test(0, ...a); new obj.Test(0, ...a); new (null || obj).Test(0, ...a); new Test(...a, ...b, 5); new obj.Test(...a, ...b, 5); new (null || obj).Test(...a, ...b, 5); new Test(...a, new Test(...c), ...b, 5); new obj.Test(...a, new Test(...c), ...b, 5); new (null || obj).Test(...a, new Test(...c), ...b, 5); new Test(...[1, 2]); new obj.Test(...[1, 2]); new (null || obj).Test(...[1, 2]); new Test(0, ...[1, 2]); new obj.Test(0, ...[1, 2]); new (null || obj).Test(0, ...[1, 2]); new Test(...[1, 2], ...[3, 4], 5); new obj.Test(...[1, 2], ...[3, 4], 5); new (null || obj).Test(...[1, 2], ...[3, 4], 5); new Test(...[1, 2], new Test(...[7, 8]), ...[3, 4], 5); new obj.Test(...[1, 2], new Test(...[7, 8]), ...[3, 4], 5); new (null || obj).Test(...[1, 2], new Test(...[7, 8]), ...[3, 4], 5); (function () { new Test(...arguments); new obj.Test(...arguments); new (null || obj).Test(...arguments); new Test(1, ...arguments); new obj.Test(1, ...arguments); new (null || obj).Test(1, ...arguments); })(7, 8, 9); `, output: ` function Test() { var i = arguments.length, argsArray = Array(i); while ( i-- ) argsArray[i] = arguments[i]; this.a = [].concat( argsArray ); console.log(JSON.stringify(this.a)); } var obj = { Test: Test }; var a = [1, 2]; var b = [3, 4]; var c = [7, 8]; new (Function.prototype.bind.apply( Test, [ null ].concat( a) )); new (Function.prototype.bind.apply( obj.Test, [ null ].concat( a) )); new (Function.prototype.bind.apply( (null || obj).Test, [ null ].concat( a) )); new (Function.prototype.bind.apply( Test, [ null ].concat( [0], a) )); new (Function.prototype.bind.apply( obj.Test, [ null ].concat( [0], a) )); new (Function.prototype.bind.apply( (null || obj).Test, [ null ].concat( [0], a) )); new (Function.prototype.bind.apply( Test, [ null ].concat( a, b, [5]) )); new (Function.prototype.bind.apply( obj.Test, [ null ].concat( a, b, [5]) )); new (Function.prototype.bind.apply( (null || obj).Test, [ null ].concat( a, b, [5]) )); new (Function.prototype.bind.apply( Test, [ null ].concat( a, [new (Function.prototype.bind.apply( Test, [ null ].concat( c) ))], b, [5]) )); new (Function.prototype.bind.apply( obj.Test, [ null ].concat( a, [new (Function.prototype.bind.apply( Test, [ null ].concat( c) ))], b, [5]) )); new (Function.prototype.bind.apply( (null || obj).Test, [ null ].concat( a, [new (Function.prototype.bind.apply( Test, [ null ].concat( c) ))], b, [5]) )); new Test(1, 2); new obj.Test(1, 2); new (null || obj).Test(1, 2); new Test(0, 1, 2); new obj.Test(0, 1, 2); new (null || obj).Test(0, 1, 2); new Test(1, 2, 3, 4, 5); new obj.Test(1, 2, 3, 4, 5); new (null || obj).Test(1, 2, 3, 4, 5); new Test(1, 2, new Test(7, 8), 3, 4, 5); new obj.Test(1, 2, new Test(7, 8), 3, 4, 5); new (null || obj).Test(1, 2, new Test(7, 8), 3, 4, 5); (function () { var i = arguments.length, argsArray = Array(i); while ( i-- ) argsArray[i] = arguments[i]; new (Function.prototype.bind.apply( Test, [ null ].concat( argsArray) )); new (Function.prototype.bind.apply( obj.Test, [ null ].concat( argsArray) )); new (Function.prototype.bind.apply( (null || obj).Test, [ null ].concat( argsArray) )); new (Function.prototype.bind.apply( Test, [ null ].concat( [1], argsArray) )); new (Function.prototype.bind.apply( obj.Test, [ null ].concat( [1], argsArray) )); new (Function.prototype.bind.apply( (null || obj).Test, [ null ].concat( [1], argsArray) )); })(7, 8, 9); ` }, { description: 'transpiles `new` with spread parameter in an arrow function', input: ` function foo (x) { if ( x ) return ref => new (bar || baz).Test( ref, ...x ); } `, output: ` function foo (x) { if ( x ) { return function (ref) { return new (Function.prototype.bind.apply( (bar || baz).Test, [ null ].concat( [ref], x ) )); }; } } ` }, { description: 'transpiles a call with spread parameter in an arrow function', input: ` function foo (x) { if ( x ) return ref => (bar || baz).Test( ref, ...x ); } `, output: ` function foo (x) { if ( x ) { return function (ref) { var ref$1; return (ref$1 = (bar || baz)).Test.apply( ref$1, [ ref ].concat( x ) ); }; } } ` }, { description: 'transpiles `new` with ...arguments in an arrow function', input: ` function foo (x) { if ( x ) return ref => new (bar || baz).Test( ref, ...arguments ); } `, output: ` function foo (x) { var arguments$1 = arguments; var i = arguments.length, argsArray = Array(i); while ( i-- ) argsArray[i] = arguments[i]; if ( x ) { return function (ref) { return new (Function.prototype.bind.apply( (bar || baz).Test, [ null ].concat( [ref], argsArray ) )); }; } } ` }, { description: 'transpiles a call with ...arguments in an arrow function', input: ` function foo (x) { if ( x ) return ref => (bar || baz).Test( ref, ...arguments ); } `, output: ` function foo (x) { var arguments$1 = arguments; var i = arguments.length, argsArray = Array(i); while ( i-- ) argsArray[i] = arguments[i]; if ( x ) { return function (ref) { var ref$1; return (ref$1 = (bar || baz)).Test.apply( ref$1, [ ref ].concat( arguments$1 ) ); }; } } ` }, { description: 'transpiles spread with template literal afterwards', input: ` [...f(b), "n"]; [...f(b), 'n']; [...f(b), \`n\`]; `, output: ` f(b).concat( ["n"]); f(b).concat( ['n']); f(b).concat( ["n"]); ` }, { description: 'transpiles spread with arrow function afterwards', input: `[...A, () => 'B']`, output: `A.concat( [function () { return 'B'; }])` }, { description: 'transpiles spread in new with arrow function afterwards', input: `new X(...A, () => 'B')`, output: `new (Function.prototype.bind.apply( X, [ null ].concat( A, [function () { return 'B'; }]) ))` }, { description: 'inlines unreasonably deep spreads', input: ` [...[...[...[1, ...[...[...[2, 3]], 4]]]]]; f(...[...[...[1, ...[...[...[2, 3]], 4]]]]); new f(...[...[...[1, ...[...[...[2, 3]], 4]]]]); `, output: ` [1, 2, 3, 4]; f(1, 2, 3, 4); new f(1, 2, 3, 4); ` }, { description: 'does not (yet) inline spread arrays with holes', input: ` [...[,]]; f(...[,]); new f(...[,]); `, output: ` [].concat( [,] ); f.apply(void 0, [,]); new (Function.prototype.bind.apply( f, [ null ].concat( [,]) )); ` }, { description: 'inlines array spreads without extraneous trailing commas', input: ` [...[]]; [...[],]; [...[x]]; [...[x,]]; [...[x, y]]; [...[x, y,]]; [...[x, y],]; [...[x, y,],]; [w, ...[]]; [w, ...[],]; [w, ...[x]]; [w, ...[x,]]; [w, ...[x, y]]; [w, ...[x, y,]]; [w, ...[x, y],]; [w, ...[x, y,],]; [...[], z]; [...[x], z]; [...[x,], z]; [...[x, y], z]; [...[x, y,], z]; [w, ...[], z]; [w, ...[x], z]; [w, ...[x,], z]; [w, ...[x, y], z]; [w, ...[x, y,], z]; `, output: ` []; []; [x]; [x ]; [x, y]; [x, y ]; [x, y ]; [x, y ]; [w ]; [w ]; [w, x]; [w, x ]; [w, x, y]; [w, x, y ]; [w, x, y ]; [w, x, y ]; [z]; [x, z]; [x, z]; [x, y, z]; [x, y, z]; [w, z]; [w, x, z]; [w, x, z]; [w, x, y, z]; [w, x, y, z]; ` }, { description: 'inlines call spreads without extraneous trailing commas', input: ` f(...[]); f(...[],); f(...[x]); f(...[x,]); f(...[x, y]); f(...[x, y,]); f(...[x, y],); f(...[x, y,],); f(w, ...[]); f(w, ...[],); f(w, ...[x]); f(w, ...[x,]); f(w, ...[x, y]); f(w, ...[x, y,]); f(w, ...[x, y],); f(w, ...[x, y,],); f(...[], z); f(...[x], z); f(...[x,], z); f(...[x, y], z); f(...[x, y,], z); f(w, ...[], z); f(w, ...[x], z); f(w, ...[x,], z); f(w, ...[x, y], z); f(w, ...[x, y,], z); `, output: ` f(); f(); f(x); f(x); f(x, y); f(x, y); f(x, y); f(x, y); f(w); f(w); f(w, x); f(w, x); f(w, x, y); f(w, x, y); f(w, x, y); f(w, x, y); f(z); f(x, z); f(x, z); f(x, y, z); f(x, y, z); f(w, z); f(w, x, z); f(w, x, z); f(w, x, y, z); f(w, x, y, z); ` }, { description: 'inlines new call spreads without extraneous trailing commas', input: ` new f(...[]); new f(...[],); new f(...[x]); new f(...[x,]); new f(...[x, y]); new f(...[x, y,]); new f(...[x, y],); new f(...[x, y,],); new f(w, ...[]); new f(w, ...[],); new f(w, ...[x]); new f(w, ...[x,]); new f(w, ...[x, y]); new f(w, ...[x, y,]); new f(w, ...[x, y],); new f(w, ...[x, y,],); new f(...[], z); new f(...[x], z); new f(...[x,], z); new f(...[x, y], z); new f(...[x, y,], z); new f(w, ...[], z); new f(w, ...[x], z); new f(w, ...[x,], z); new f(w, ...[x, y], z); new f(w, ...[x, y,], z); `, output: ` new f(); new f(); new f(x); new f(x); new f(x, y); new f(x, y); new f(x, y); new f(x, y); new f(w); new f(w); new f(w, x); new f(w, x); new f(w, x, y); new f(w, x, y); new f(w, x, y); new f(w, x, y); new f(z); new f(x, z); new f(x, z); new f(x, y, z); new f(x, y, z); new f(w, z); new f(w, x, z); new f(w, x, z); new f(w, x, y, z); new f(w, x, y, z); ` }, { description: 'transpiles a first spread element comprising a ternary operator', input: '[...a ? b : c, d]', output: '( a ? b : c ).concat( [d])', } ]; buble-0.19.8/test/samples/template-strings.js000066400000000000000000000104321350705536200211730ustar00rootroot00000000000000module.exports = [ { description: 'transpiles an untagged template literal', input: 'var str = `foo${bar}baz`;', output: `var str = "foo" + bar + "baz";` }, { description: 'handles arbitrary whitespace inside template elements', input: 'var str = `foo${ bar }baz`;', output: `var str = "foo" + bar + "baz";` }, { description: 'transpiles an untagged template literal containing complex expressions', input: 'var str = `foo${bar + baz}qux`;', output: `var str = "foo" + (bar + baz) + "qux";` }, { description: 'transpiles a template literal containing single quotes', input: "var singleQuote = `'`;", output: `var singleQuote = "'";` }, { description: 'transpiles a template literal containing double quotes', input: 'var doubleQuote = `"`;', output: `var doubleQuote = "\\"";` }, { description: 'does not transpile tagged template literals', input: 'var str = x`y`', error: /Transforming tagged template strings is not fully supported/ }, { description: 'transpiles tagged template literals with `transforms.dangerousTaggedTemplateString = true`', options: { transforms: { dangerousTaggedTemplateString: true } }, input: 'var str = x`y${(() => 42)()}`;', output: `var templateObject = Object.freeze(["y", ""]);\nvar str = x(templateObject, (function () { return 42; })());` }, { description: 'transpiles tagged template literals with `transforms.dangerousTaggedTemplateString = true`', options: { transforms: { dangerousTaggedTemplateString: true } }, input: 'var str = x`${(() => 42)()}y`;', output: `var templateObject = Object.freeze(["", "y"]);\nvar str = x(templateObject, (function () { return 42; })());` }, { description: 'reuses quasi array for identical tagged template strings', options: { transforms: { dangerousTaggedTemplateString: true } }, input: 'x`a${a}b`, x`a${b}b`, x`b${c}a`', output: `var templateObject$1 = Object.freeze(["b", "a"]);\nvar templateObject = Object.freeze(["a", "b"]);\nx(templateObject, a), x(templateObject, b), x(templateObject$1, c)` }, { description: 'reuses quasi array for identical tagged template strings in strict mode', options: { transforms: { dangerousTaggedTemplateString: true } }, input: '"use strict";\nx`a${a}b`, x`a${b}b`, x`b${c}a`', output: `"use strict";\nvar templateObject$1 = Object.freeze(["b", "a"]);\nvar templateObject = Object.freeze(["a", "b"]);\nx(templateObject, a), x(templateObject, b), x(templateObject$1, c)` }, { description: 'correctly positions the templateObject at the start of the source file', options: { transforms: { dangerousTaggedTemplateString: true } }, input: '() => tagged`template literal`', output: 'var templateObject = Object.freeze(["template literal"]);\n!function() { return tagged(templateObject); }' }, { description: 'parenthesises template strings as necessary', input: 'var str = `x${y}`.toUpperCase();', output: 'var str = ("x" + y).toUpperCase();' }, { description: 'does not parenthesise plain template strings', input: 'var str = `x`.toUpperCase();', output: 'var str = "x".toUpperCase();' }, { description: 'does not parenthesise template strings in arithmetic expressions', input: 'var str = `x${y}` + z; var str2 = `x${y}` * z;', output: 'var str = "x" + y + z; var str2 = ("x" + y) * z;' }, { description: 'can be disabled with `transforms.templateString === false`', options: { transforms: { templateString: false } }, input: 'var a = `a`, b = c`b`;', output: 'var a = `a`, b = c`b`;' }, { description: 'skips leading empty string if possible', input: 'var str = `${a} ${b}`', output: 'var str = a + " " + b' }, { description: 'includes leading empty string if necessary', input: 'var str = `${a}${b}`', output: 'var str = "" + a + b' }, { description: 'closes parens if final empty string is omitted', input: 'var str = `1 + 1 = ${1 + 1}`;', output: 'var str = "1 + 1 = " + (1 + 1);' }, { description: 'allows empty template string', input: 'var str = ``;', output: 'var str = "";' }, { description: 'concats expression with variable', input: 'var str = `${a + b}${c}`;', output: 'var str = "" + (a + b) + c;' }, { description: 'interpolations inside interpolations', input: 'var string = `foo${`${bar}`}`', output: `var string = "foo" + ("" + bar)` } ]; buble-0.19.8/test/samples/trailing-function-commas.js000066400000000000000000000034671350705536200226140ustar00rootroot00000000000000module.exports = [ { description: 'strips trailing commas in call arguments', input: ` f(a,)`, output: ` f(a)` }, { description: 'strips trailing commas in function expression arguments', input: ` let f = function (a,) {}`, output: ` var f = function (a) {}` }, { description: 'strips trailing commas in normal function declaration arguments', input: ` function f(a,) {}`, output: ` function f(a) {}` }, { description: 'strips trailing commas in method arguments', input: ` class A { f(a,) {} }`, output: ` var A = function A () {}; A.prototype.f = function f (a) {};` }, { description: 'strips trailing commas in arrow function declaration arguments', input: ` ((a,) => {})`, output: ` (function (a) {})` }, { description: 'strips trailing commas after destructured argument in arrow function declaration arguments', input: ` ((a,[b],{c},) => {})`, output: ` (function (a,ref,ref$1) { var b = ref[0]; var c = ref$1.c; })` }, { description: 'strips trailing commas in new expression arguments', input: ` new f(a,)`, output: ` new f(a)` }, { description: 'keeps commas in trailing comments in normal function declaration arguments', input: ` function f(a/*,*/) {}`, output: ` function f(a/*,*/) {}` }, { description: 'strips trailing commas after comments in normal function declaration arguments', input: ` function f(a/*a*/,) {}`, output: ` function f(a/*a*/) {}` }, { description: 'does not freeze on multiline calls without trailing comma', input: ` f(a// )`, output: ` f(a// )` }, { description: 'does not remove commas after closing parens', input: ` function x(a// ){return{b:1,c:2}}`, output: ` function x(a// ){return{b:1,c:2}}` } ]; buble-0.19.8/test/test.js000066400000000000000000000204031350705536200152030ustar00rootroot00000000000000var path = require('path'); var fs = require('fs'); var rimraf = require('rimraf'); var child_process = require('child_process'); var assert = require('assert'); var glob = require('glob'); var SourceMapConsumer = require('source-map').SourceMapConsumer; var getLocation = require('./utils/getLocation.js'); var buble = require('..'); require('source-map-support').install(); require('console-group').install(); function equal(a, b) { assert.equal(showInvisibles(a), showInvisibles(b)); } function showInvisibles(str) { return str .replace(/^ +/gm, spaces => repeat('•', spaces.length)) .replace(/ +$/gm, spaces => repeat('•', spaces.length)) .replace(/^\t+/gm, tabs => repeat('› ', tabs.length)) .replace(/\t+$/gm, tabs => repeat('› ', tabs.length)); } function repeat(str, times) { var result = ''; while (times--) result += str; return result; } const subsetIndex = process.argv.indexOf('--subset'); const subset = ~subsetIndex ? process.argv[subsetIndex + 1].split(',').map(file => `${file}.js`) : null; const subsetFilter = subset ? file => ~subset.indexOf(file) : () => true; describe('buble', () => { fs .readdirSync('test/samples') .filter(subsetFilter) .forEach(file => { if (!/\.js$/.test(file)) return; // avoid vim .js.swp files var samples = require('./samples/' + file); describe(path.basename(file), () => { samples.forEach(sample => { (sample.solo ? it.only : sample.skip ? it.skip : it)( sample.description, () => { if (sample.error) { assert.throws(() => { buble.transform(sample.input, sample.options); }, sample.error); } else { equal( buble.transform(sample.input, sample.options).code, sample.output ); } } ); }); }); }); if (subset) return; describe('cli', () => { fs.readdirSync('test/cli').forEach(dir => { if (dir[0] === '.') return; // .DS_Store it(dir, done => { dir = path.resolve('test/cli', dir); rimraf.sync(path.resolve(dir, 'actual')); fs.mkdirSync(path.resolve(dir, 'actual')); var binFile = path.resolve(__dirname, '../bin/buble'); var commandFile = path.resolve(dir, 'command.sh'); var command = fs .readFileSync(commandFile, 'utf-8') .replace('buble', 'node "' + binFile + '"'); child_process.exec( command, { cwd: dir }, (err, stdout, stderr) => { if (err) return done(err); if (stdout) console.log(stdout); if (stderr) console.error(stderr); function catalogue(subdir) { subdir = path.resolve(dir, subdir); return glob .sync('**/*.js?(.map)', { cwd: subdir }) .sort() .map(name => { var contents = fs .readFileSync(path.resolve(subdir, name), 'utf-8') .replace(/\r\n/g, '\n') .trim(); if (path.extname(name) === '.map') { contents = JSON.parse(contents); } return { name, contents }; }); } var expected = catalogue('expected'); var actual = catalogue('actual'); try { assert.deepEqual(actual, expected); done(); } catch (err) { done(err); } } ); }); }); }); describe('errors', () => { it('reports the location of a syntax error', () => { var source = `var 42 = nope;`; try { buble.transform(source); } catch (err) { assert.equal(err.name, 'SyntaxError'); assert.deepEqual(err.loc, { line: 1, column: 4 }); assert.equal(err.message, 'Unexpected token (1:4)'); assert.equal(err.snippet, `1 : var 42 = nope;\n ^`); assert.equal( err.toString(), `SyntaxError: Unexpected token (1:4)\n1 : var 42 = nope;\n ^` ); } }); it('reports the location of a compile error', () => { var source = `const x = 1; x++;`; try { buble.transform(source); } catch (err) { assert.equal(err.name, 'CompileError'); assert.equal(err.loc.line, 1); assert.equal(err.loc.column, 13); assert.equal(err.message, 'x is read-only (1:13)'); assert.equal( err.snippet, `1 : const x = 1; x++;\n ^` ); assert.equal( err.toString(), `CompileError: x is read-only (1:13)\n1 : const x = 1; x++;\n ^` ); } }); }); describe('target', () => { it('determines necessary transforms for a target environment', () => { var transforms = buble.target({ chrome: 49 }); assert.ok(transforms.moduleImport); assert.ok(!transforms.arrow); }); it('returns lowest common denominator support info', () => { var transforms = buble.target({ chrome: 49, node: 5 }); assert.ok(transforms.defaultParameter); assert.ok(!transforms.arrow); }); it('only applies necessary transforms', () => { var source = ` const power = ( base, exponent = 2 ) => Math.pow( base, exponent );`; var result = buble.transform(source, { target: { chrome: 49, node: 5 } }).code; assert.equal( result, ` var power = ( base, exponent ) => { if ( exponent === void 0 ) exponent = 2; return Math.pow( base, exponent ); };` ); }); }); describe('sourcemaps', () => { it('generates a valid sourcemap', () => { var map = buble.transform('').map; assert.equal(map.version, 3); }); it('uses provided file and source', () => { var map = buble.transform('', { file: 'output.js', source: 'input.js' }).map; assert.equal(map.file, 'output.js'); assert.deepEqual(map.sources, ['input.js']); }); it('includes content by default', () => { var source = `let { x, y } = foo();`; var map = buble.transform(source).map; assert.deepEqual(map.sourcesContent, [source]); }); it('excludes content if requested', () => { var source = `let { x, y } = foo();`; var map = buble.transform(source, { includeContent: false }).map; assert.deepEqual(map.sourcesContent, [null]); }); it('locates original content', () => { var source = `const add = ( a, b ) => a + b;`; var result = buble.transform(source, { file: 'output.js', source: 'input.js' }); var smc = new SourceMapConsumer(result.map); var location = getLocation(result.code, 'add'); var expected = getLocation(source, 'add'); var actual = smc.originalPositionFor(location); assert.deepEqual(actual, { line: expected.line, column: expected.column, source: 'input.js', name: null }); location = getLocation(result.code, 'a +'); expected = getLocation(source, 'a +'); actual = smc.originalPositionFor(location); assert.deepEqual(actual, { line: expected.line, column: expected.column, source: 'input.js', name: null }); }); it('recovers names', () => { var source = ` const foo = 1; if ( x ) { const foo = 2; }`; var result = buble.transform(source, { file: 'output.js', source: 'input.js' }); var smc = new SourceMapConsumer(result.map); var location = getLocation(result.code, 'var'); var actual = smc.originalPositionFor(location); assert.equal(actual.name, 'const'); location = getLocation(result.code, 'var', location.char + 1); actual = smc.originalPositionFor(location); assert.equal(actual.name, 'const'); location = getLocation(result.code, 'foo$1', location.char + 1); actual = smc.originalPositionFor(location); assert.equal(actual.name, 'foo'); }); it('handles moved content', () => { var source = ` for ( let i = 0; i < 10; i += 1 ) { const square = i * i; setTimeout( function () { log( square ); }, i * 100 ); }`; var result = buble.transform(source, { file: 'output.js', source: 'input.js' }); var smc = new SourceMapConsumer(result.map); var location = getLocation(result.code, 'i < 10'); var expected = getLocation(source, 'i < 10'); var actual = smc.originalPositionFor(location); assert.deepEqual(actual, { line: expected.line, column: expected.column, source: 'input.js', name: null }); location = getLocation(result.code, 'setTimeout'); expected = getLocation(source, 'setTimeout'); actual = smc.originalPositionFor(location); assert.deepEqual(actual, { line: expected.line, column: expected.column, source: 'input.js', name: null }); }); }); }); buble-0.19.8/test/utils/000077500000000000000000000000001350705536200150275ustar00rootroot00000000000000buble-0.19.8/test/utils/getLocation.js000066400000000000000000000010331350705536200176320ustar00rootroot00000000000000module.exports = function getLocation(source, search, start) { if (typeof search === 'string') { search = source.indexOf(search, start); } var lines = source.split('\n'); var len = lines.length; var lineStart = 0; var i; for (i = 0; i < len; i += 1) { var line = lines[i]; var lineEnd = lineStart + line.length + 1; // +1 for newline if (lineEnd > search) { return { line: i + 1, column: search - lineStart, char: i }; } lineStart = lineEnd; } throw new Error('Could not determine location of character'); };