109 Commits

Author SHA1 Message Date
Nicolò Ribaudo
2297e2d764
Fix a regression introduced in #7040 (#7116) 2017-12-28 22:15:53 +01:00
Nicolò Ribaudo
68476b6ddd
Make .insert{Before,After} work by default when the parent is an eport declaration (#7040) 2017-12-19 00:05:29 +01:00
Brian Ng
c583a04a55 Fix setting deopt properly after evaluating multiple expressions (#6882) 2017-11-22 20:06:57 -05:00
Nicolò Ribaudo
9a231c5671 Remove support for flow bindings (#6528)
Flow bindings have been deprecated for a while.
The reason behind this change is that `declare var foo`
doesn't introduce a new local binding, but it represents
a global one.
2017-11-09 12:29:04 -08:00
Henry Zhu
691f90a774 Scoped: change test imports to @babel/ [skip ci] 2017-10-16 22:49:56 -04:00
Abhilash Singh
6230855b71 unshiftContainer seems to incorrectly handle function params #6150 (#6354) 2017-09-30 09:14:51 -04:00
Justin Ridgewell
3746273eda Path#ensureBlock keeps path context (#6337)
* Path#ensureBlock keeps path context

This ensures that if you're inside an ArrowFunction with an expression body (say, you're on the BooleanLiteral in `() => true`), you don't suddenly lose your path context after inserting a variable.

This is because of 82d8aded8e (diff-9e0668ad44535be897b934e7077ecea5R14). Basically, an innocent `Scope#push` caused my visitor to suddenly stop working. Now, we mutate the Path so it's still in the tree.

* Tests
2017-09-29 19:00:10 -04:00
Logan Smyth
20679979fc Remove the unused 'scope' param from 'traverse.hasType'. 2017-09-12 16:48:05 -07:00
Justin Ridgewell
4daf11528c Return inserted/replaced paths (#5710)
* Return inserted/replaced paths

This gives `Path`’s replacement and insertion methods a consistent
return value: the inserted/replaced paths.

Before, they could return `undefined`, a `node`, or a the current path
inside an array. It was kinda pointless.  But now they always return an
array of paths, which is useful for solving
https://github.com/babel/babel/pull/4935#discussion_r96151368.

* Return inserted nodes and not BlockStatement

Addded test for bug #4363

* Cleanups

- `#replaceWith` will now return the current path if it's the same node
- `#insertAfter` and `#insertBefore` use public Path APIs now
- Makes container insertion faster (single splice call)
- Use public APIs in container insertion
- Replacing a statement with an expression returns the expression's path
- Replacing an expression with multiple statements returns the inserted
  closure's body's paths.
2017-09-11 16:07:04 -04:00
Ruben Verborgh
6560a29c36 Redeclaring a variable counts as a modification (#6219)
* Redeclaring a variable counts as a modification.

Fixes #6217.

* Remove "existing" logic from Binding.

Was added in #5745, but no longer triggered since 6536e605a.
2017-09-08 23:02:26 -04:00
Daniel Tschinder
44f6ff5e85 Update prettier, eslint + plugins, flow, husky and lint-staged (#6183) 2017-08-31 22:56:29 +02:00
Daniel Tschinder
0189b38702
Merge branch '6.x' into 7.0
# Conflicts:
#	CONTRIBUTING.md
#	Makefile
#	README.md
#	lerna.json
#	lib/types.js
#	package.json
#	packages/babel-cli/package.json
#	packages/babel-code-frame/package.json
#	packages/babel-core/package.json
#	packages/babel-core/test/fixtures/transformation/misc/regression-2892/expected.js
#	packages/babel-generator/package.json
#	packages/babel-generator/src/generators/flow.js
#	packages/babel-generator/src/index.js
#	packages/babel-generator/test/fixtures/flow/declare-statements/expected.js
#	packages/babel-generator/test/fixtures/flow/object-literal-types/expected.js
#	packages/babel-generator/test/fixtures/flow/opaque-type-alias/expected.js
#	packages/babel-helper-bindify-decorators/package.json
#	packages/babel-helper-builder-binary-assignment-operator-visitor/package.json
#	packages/babel-helper-builder-conditional-assignment-operator-visitor/package.json
#	packages/babel-helper-builder-react-jsx/package.json
#	packages/babel-helper-call-delegate/package.json
#	packages/babel-helper-define-map/package.json
#	packages/babel-helper-explode-assignable-expression/package.json
#	packages/babel-helper-explode-class/package.json
#	packages/babel-helper-fixtures/package.json
#	packages/babel-helper-function-name/package.json
#	packages/babel-helper-get-function-arity/package.json
#	packages/babel-helper-hoist-variables/package.json
#	packages/babel-helper-optimise-call-expression/package.json
#	packages/babel-helper-plugin-test-runner/package.json
#	packages/babel-helper-regex/package.json
#	packages/babel-helper-remap-async-to-generator/package.json
#	packages/babel-helper-replace-supers/package.json
#	packages/babel-helper-transform-fixture-test-runner/package.json
#	packages/babel-helpers/package.json
#	packages/babel-plugin-transform-async-generator-functions/package.json
#	packages/babel-plugin-transform-async-to-generator/package.json
#	packages/babel-plugin-transform-async-to-module-method/package.json
#	packages/babel-plugin-transform-class-constructor-call/package.json
#	packages/babel-plugin-transform-class-properties/package.json
#	packages/babel-plugin-transform-decorators/package.json
#	packages/babel-plugin-transform-es2015-block-scoping/package.json
#	packages/babel-plugin-transform-es2015-classes/package.json
#	packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T6755/expected.js
#	packages/babel-plugin-transform-es2015-computed-properties/package.json
#	packages/babel-plugin-transform-es2015-duplicate-keys/package.json
#	packages/babel-plugin-transform-es2015-function-name/package.json
#	packages/babel-plugin-transform-es2015-modules-amd/package.json
#	packages/babel-plugin-transform-es2015-modules-commonjs/package.json
#	packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js
#	packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/interop/export-destructured/expected.js
#	packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/export-const-destructuring-object-default-params/expected.js
#	packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/export-const-destructuring-object-rest/expected.js
#	packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/export-const-destructuring-object/expected.js
#	packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/options.json
#	packages/babel-plugin-transform-es2015-modules-systemjs/package.json
#	packages/babel-plugin-transform-es2015-modules-umd/package.json
#	packages/babel-plugin-transform-es2015-object-super/package.json
#	packages/babel-plugin-transform-es2015-parameters/package.json
#	packages/babel-plugin-transform-es2015-shorthand-properties/package.json
#	packages/babel-plugin-transform-es2015-sticky-regex/package.json
#	packages/babel-plugin-transform-es2015-unicode-regex/package.json
#	packages/babel-plugin-transform-es5-property-mutators/package.json
#	packages/babel-plugin-transform-exponentiation-operator/package.json
#	packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/opaque-type-alias/expected.js
#	packages/babel-plugin-transform-object-rest-spread/package.json
#	packages/babel-plugin-transform-object-rest-spread/src/index.js
#	packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/nested-2/expected.js
#	packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/nested/expected.js
#	packages/babel-plugin-transform-proto-to-assign/package.json
#	packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/regression-node-type-export-default/expected.js
#	packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/regression-node-type-export/expected.js
#	packages/babel-plugin-transform-react-display-name/package.json
#	packages/babel-plugin-transform-react-display-name/src/index.js
#	packages/babel-plugin-transform-react-display-name/test/fixtures/display-name/assignment-expression/expected.js
#	packages/babel-plugin-transform-react-display-name/test/fixtures/display-name/nested/expected.js
#	packages/babel-plugin-transform-react-display-name/test/fixtures/display-name/object-property/expected.js
#	packages/babel-plugin-transform-react-display-name/test/fixtures/display-name/variable-declarator/expected.js
#	packages/babel-plugin-transform-react-jsx-compat/package.json
#	packages/babel-plugin-transform-react-jsx/package.json
#	packages/babel-plugin-transform-regenerator/package.json
#	packages/babel-plugin-transform-regenerator/test/fixtures/regression/6733/expected.js
#	packages/babel-plugin-transform-regenerator/test/fixtures/regression/T7041/expected.js
#	packages/babel-plugin-transform-regenerator/test/fixtures/variable-renaming/retain-lines/expected.js
#	packages/babel-plugin-transform-runtime/README.md
#	packages/babel-plugin-transform-runtime/test/fixtures/runtime/custom-runtime/expected.js
#	packages/babel-plugin-transform-runtime/test/fixtures/runtime/full/expected.js
#	packages/babel-plugin-transform-runtime/test/fixtures/runtime/regenerator-runtime/expected.js
#	packages/babel-plugin-transform-strict-mode/package.json
#	packages/babel-polyfill/package.json
#	packages/babel-preset-es2015/package.json
#	packages/babel-preset-es2016/package.json
#	packages/babel-preset-es2017/package.json
#	packages/babel-preset-latest/package.json
#	packages/babel-preset-react/package.json
#	packages/babel-preset-stage-0/package.json
#	packages/babel-preset-stage-1/package.json
#	packages/babel-preset-stage-2/package.json
#	packages/babel-preset-stage-3/package.json
#	packages/babel-register/README.md
#	packages/babel-register/package.json
#	packages/babel-runtime/package.json
#	packages/babel-template/package.json
#	packages/babel-traverse/package.json
#	packages/babel-traverse/src/scope/lib/renamer.js
#	packages/babel-traverse/test/evaluation.js
#	packages/babel-traverse/test/replacement.js
#	packages/babel-types/README.md
#	packages/babel-types/package.json
#	packages/babel-types/src/converters.js
#	packages/babel-types/src/definitions/core.js
#	packages/babel-types/src/definitions/es2015.js
#	packages/babel-types/src/definitions/flow.js
#	packages/babel-types/test/converters.js
#	packages/babel-types/test/validators.js
#	scripts/generate-interfaces.js
#	yarn.lock
2017-08-31 17:44:17 +02:00
Justin Ridgewell
4b297907d1 Move fix into #checkBlockScopedCollisions 2017-08-25 19:23:11 -04:00
Henry Zhu
0f823beeb1 Newlines in fixtures (#6044)
* write newlines for fixtures

* rerun fixtures
2017-08-02 15:35:29 -04:00
Peeyush Kushwaha
2225892348 Use first binding for multiple var declarations (#5745)
* Use first binding for multiple var declarations
Since var declarations after initial binding have no effect, use the
first declaration. Fixes #2378

* Include hoisted function bindings

* Missing newline in expected.js

* Simplify constantViolations in new Binding on existing

* clarify comment language
2017-07-24 14:43:17 -04:00
Justin Ridgewell
8a98141b60 Fix a few type inferences (#5835) 2017-07-20 11:38:12 -04:00
Justin Ridgewell
63204ae51e Remove maybePopFromStatements (#5945)
It prevented you from pushing into the `params` of a function.

```js
fnpath.pushContainer("params", t.identifier("memo"))
```
2017-07-18 14:55:33 -04:00
Ash
960e1708a1 babel-traverse: Mark appropriate template literals as pure (#5914)
* Identify pure template literals

* Mark template literals as pure where possible

* Changes based on code review

* nit
2017-07-11 17:42:34 -04:00
Daniel Tschinder
b3372a572d Remove whitespace generation (#5833)
* Remove whitespace generation and rely on default printing

Changes to printing:
* Add newline after last empty SwitchCase
* Add newlines around block comments if they are non-flow comments or contain newlines

* Fix a few more fixtures
2017-06-27 21:57:02 -05:00
Brian Ng
e4b35f680d
Run prettier 2017-06-27 12:15:00 -05:00
Joseph Frazier
a330cf2b09 Add support for evaluating String.raw expressions (#5681)
* Add support for evaluating `String.raw` expressions

* Dedupe evaluation code for template literal quasis

* Check scoping in `String.raw` evaluation
  This addresses https://github.com/babel/babel/pull/5681#discussion_r114203497

* Ensure that `tag` is a MemberExpression in `String.raw` evaluation
  This addresses https://github.com/babel/babel/pull/5681#discussion_r114203555

* babel-traverse: Move evaluateQuasis() outside _evaluate()
2017-06-24 16:00:42 -04:00
Mauro Bringolf
c142bbc429 Remove duplicated getStatementParent and refactor requires to imports in tests (#5746)
* Additional testcase and require->import refactorings

* Removed duplicated getStatementParent function. Refactored all babel-traverse tests to use ESmodules
2017-05-31 15:33:25 -04:00
Mauro Bringolf
f0d7d580d5 Added individual test cases for possible errors with path.replaceWith (#5779) 2017-05-27 00:22:26 -04:00
Logan Smyth
14584c218c Kill the "shadow-functions.js" internal plugin in favor of an explicit helper (#5677)
* Handle arrow function processing via shared API rather than default plugin.

* Fix a few small PR comments.

* Preserve existing spec arrow 'this' rewrites, and support spec in subclass constructors.
2017-05-05 13:27:18 -07:00
ssuman
412180e203 Increase the code coverage for traverse evaluation (#5363)
* When applied this commit will increase the code coverage for evaluation.js

* Fixing linting issues
2017-04-09 16:49:37 -07:00
MrSpider
fd3a2c285a Fix replacing function declaration in export default (fixes #4468) (#5456) 2017-04-06 11:40:31 -04:00
Boopathi Rajaa
c9a851a218 Cleanup traverse cache APIs (#5494) 2017-03-23 12:00:28 -04:00
Damien Maillard
299e51298c Fix path.remove() leading & trailing comments sharing (#5504) 2017-03-23 11:55:14 -04:00
MrSpider
5287e13817 Fix replacing function declaration in export default (fixes #4468) (#5444) 2017-03-10 11:41:03 -08:00
Brian Ng
8a82cc060a Run new lint rules (#5413) 2017-03-04 10:46:01 -05:00
Jason Laster
ff2c24eed2 Add test for reference paths (#5296) 2017-02-15 15:05:31 -05:00
Logan Smyth
454933ef76 Revert "Rewrite Hub as interface #5047" (#5306) 2017-02-13 18:15:50 -08:00
Yongxu Ren
2985597d40 Rewrite Hub as interface #5047 (#5050)
* Rewrite Hub as interface #5047

* Update index.js
2017-02-13 12:49:10 -08:00
Boopathi Rajaa
f8ffe03e79 Deopt evaluation of undefined with a local binding. Fix #5204 (#5206) 2017-02-08 10:37:14 -05:00
Vicente Jr Yuchitcho
1ba4a3fe5d Add path sibling traversal methods (#5230)
* getPrevSibling
* getNextSibling
* getAllNextSiblings
* getAllPrevSiblings
2017-02-07 11:17:50 -05:00
Logan Smyth
b845f2b69d Re-enable the max-len ESLint rule. (#5265) 2017-02-04 11:07:15 -05:00
Brian Ng
8c35b320d3 Bump eslint-config-babel and fix lint (#5129) 2017-01-17 10:51:16 +01:00
Andres Suarez
85b3aec747 Use native or lodash util module where full "lodash" is required 2017-01-15 13:35:00 -08:00
Henry Zhu
672adba9a1 enable prefer const (#5113) 2017-01-14 09:48:52 -05:00
Daniel Tschinder
dc617129f6 Optimize removal-hooks for ArrowFunctions (#5076) 2017-01-09 09:05:23 -05:00
Boopathi Rajaa
73ff13f326 Add getBindingIdentifierPaths/getOuterBindingIdentifierPaths (#4876) 2016-12-08 12:43:14 -05:00
Boopathi Rajaa
7e020272c1 Fix path.evaluate for references before declarations (#4875) 2016-11-20 22:44:56 -05:00
Boopathi Rajaa
55a47a8819 Add path utilities isAncestor and isDescendant (#4836)
* Add path utilities isAncestor and isDescendant

* Create ancestry.js
2016-11-15 16:36:45 -05:00
Boopathi Rajaa
dbc1371ba9 Add clearCache and clearPath as separate APIs under traverse (#4835) 2016-11-15 10:48:59 -05:00
Moti Zilberman
fd4667e649 Increase test coverage (#4742)
* Add tests for path type inferers

* Add test for babel-types.valueToNode

* Add tests for babel-types.toKeyAlias

* Add tests for babel-types.toStatement

* Add tests for babel-types.toExpression

* Lint fixes in babel-traverse/test/inference
2016-10-23 10:51:09 +02:00
Juriy Zaytsev
beda884f41 Make getBinding ignore labels; add Scope#getLabel, Scope#registerLabel (#4758)
* Make getBinding ignore labels; add Scope#getLabel, Scope#registerLabel

* generateUid: account for labels again
2016-10-21 17:19:59 -04:00
Andrew Levine
9f8ab29213 Change usage of "suite"/"test" in unit-tests to "describe"/"it" (#4734)
Fixes #4733
2016-10-15 18:45:35 -04:00
Andrew Levine
c0038221d7 Run ESLint on test files, and fix lint errors in test files (#4732) 2016-10-15 18:27:48 -04:00
Boopathi Rajaa
183d9570f9 Fix bug where redeclaration of var doesn't deopt (#3559)
* Fix bug where redeclaration of var doesn't deopt. (Close T7470)

* [evaluate] Add tests for cases - let/const/different scopes
2016-08-17 19:23:09 -04:00
Erik Desjardins
aeb42c2228 Fix bug where path.evaluate treats repeated identifiers as undefined (#3557)
* babel-traverse: add test to demonstrate repeated identifiers being evaluated to `false`

* fix typo: `value` -> `val`

* path.evaluate: only mark item as resolved if we're confident
2016-08-04 16:58:41 -04:00