86 Commits

Author SHA1 Message Date
Erlend Tobiassen
740064ced7 Fix missing ClassDeclaration references after scope#crawl (#11011)
* Bug replication test

* Simplify test

* Fixes #10896

* Merge path.crawl `ClassDeclaration` and `Declaration` visitors

Merged to avoid subtle assumption that `Declaration` is called before `ClassDeclaration`

* Move registartion of class id in crawl to BlockScoped

* Add some assertions to crawl test
2020-01-19 21:32:05 -05:00
Huáng Jùnliàng
fc5365fe4a
Fix parameter expression get binding (#10912)
* fix: parameter expression closure should not have access to the declaration inside function body

* fix: renameVisitor should skip when a pattern is a scope

* address review comments
2019-12-24 15:18:46 -05:00
Kenza Houmani
2b082601a7 Fix parentheses on replaceWithMultiple for JSX (#10598)
* Closes #9851 Fix parentheses on replaceWithMultiple for JSX

* Rename test

* Use generate(ast) directly
2019-11-11 12:36:17 +03:00
Nicolò Ribaudo
43b623c1f1
[traverse] Allow skipping nodes inserted with .replaceWith() (#9777)
* Avoid regression
2019-10-18 00:16:35 +02:00
Nicolò Ribaudo
99035ca96e
Don't use args rest/spread to hoist super method calls (#9939)
* Don't use args rest/spread to hoist super method calls

* Hoist this in hoisted super method calls

* Make the code more readable

Review by edoardocavazza
2019-10-11 10:18:54 +02:00
Tan Li Hau
b4c9cb0222 Fixed computed keys for class expression (#10029)
* test case for insertBefore for jsx

* fix unshiftContainer and insertBefore

* use path.scope.push

* add test making sure computedKeys var declaration at the right block

* add comment

* nit [skip ci]
2019-05-28 23:07:55 +02:00
Grégoire Geis
72161a64b2 @babel/traverse: Fix NodePath.getData (#9415)
* @babel/traverse: Fix NodePath.getData

Currently, if the obtained value is `false`, it will be replaced by the given default value, which is invalid. This makes sure that we only set the default value when the value is `undefined`, instead of falsy.

* Add test and fix object protoype

* Allow false as default value
2019-03-26 16:58:38 -07:00
Pelle Nielsen
a35e5a314a Fix TSFunctionType visitors definition (#9692)
When traversing a tree parsing for TypeScript syntax and hitting a `TSFunctionType` node, the `typeParameters` and `typeAnnotation` fields are correctly visited but the `parameters` field isn't. As a result visitors by default don't visit `foo` below:

```
var x: (foo) => void; // foo is never visited
```
```
module.exports = function() {
  return {
    visitor: {
      Identifier(path) {
        if (path.node.name == "foo") {
          // Never hit because it's nested within TSFunctionType.parameters
          path.node.name = "bar";
        }
      }
    }
  };
}
```

It appears to be a bug in babel-types/src/definitions/typescript.js which omits `parameters` in the visitors list for `fnOrCtr`. Fixed by adding it.
2019-03-16 09:24:23 +01:00
Daniel Tschinder
b32d271fee
Migrate some duplicate binding tests to traverse (#9532)
* Migrate try-catch duplicate error

* Remove exception for functions and let in the same scope

* Migrate duplicate bindings tests to traverse

* Add test for subscope and let/const

* Add more test cases
2019-02-19 21:25:49 -08:00
Daniel Tschinder
a1ea765b95
Make tests spec compliant and avoid duplicate declarations in input files (#9522) 2019-02-18 16:14:35 -08:00
Joel Denning
d305419da6 Not depending on return value of super(). Fixes #9020. (#9060)
* Not depending on return value of super(). Fixes #9020.

* Feedback from nicolo-ribaudo

* Feedback -- fixing bad call to replaceWithMultiple
2018-12-04 21:50:17 +01:00
Nicolò Ribaudo
b706e34fc8 [decorators] Correctly insert _initialize(this) after super(). (#8970)
* [decorators] Correctly insert `_initialize(this)` after `super()`.

This commit fixes to problem:
1) After `super();` statements, `_initialize(this)` was inserted without
   a trailing semicolon.
2) `(0, super())` causes an infinite recursion.

* Fix tests

* Add test
2018-11-06 21:58:09 -08:00
Nicolò Ribaudo
24c4901ff5
Remove Babylon plugins for features already merged to the ECMAScript spec (#8448)
These are now enabled by default:
- objectRestSpread (2018)
- asyncGenerators (2018)
- optionalCatchBInding (2019)
- jsonStrings (2019)

TODO (after this commit):
- [ ] Deprecate the `@babel/plugin-syntax-*` packages.
- [ ] Deprecate the `@babel/plugin-proposal-*` packages.
- [ ] Create the `@babel/plugin-transform-*` packages.
2018-11-05 23:48:06 +01:00
Cyp
e541d6031a fix: Expression x === 'y' && '' should not evaluate to undefined. (#8880)
Fixes https://github.com/babel/minify/issues/908.
2018-10-16 21:25:49 +02:00
Kevin Thomas
842c164be5 Insertafter jsx fix (#8833)
* Add check for JSXElement

* Add test
2018-10-10 10:10:20 -06:00
Logan Smyth
79b2af5997
Format fixture JSON with Prettier. (#8658) 2018-09-09 17:57:52 -07:00
Rafael de Oleza
22bcfbe469 Fix path.scope.rename() to not change break clauses (#8478)
* Make labels on break and continue statements not referenced

* Add test for imports and labels with the same name
2018-08-23 14:20:57 -07:00
Logan Smyth
b04de1196a
Rename exported functions where name conflicts with param. (#8505) 2018-08-21 13:54:29 -07:00
Yongxu Ren
0fd3da110d Rewrite Hub as interface #5047 2018-08-20 19:30:29 +02:00
Chaitanya Kumar Kamatham
daf0ca8680 Rename "babylon" to "@babel/parser" (#7937) 🎉 2018-05-19 00:03:05 -04:00
Rubén Norte
bc6f0f989d Re-add support for local Flow bindings (TypeAlias, OpaqueTypeAlias and Interface) (#7900) 2018-05-17 10:54:14 -07:00
Justin Ridgewell
7ae724f553
Add Path#isInStrictMode (#7712)
* Add Path#isInStrictMode

* Fix undefined directives

* Explicitly return for arrow expressions
2018-04-11 09:13:38 -04:00
Deven Bansod
8b57a3e3b9 Migrate a few packages' tests to use Jest Expect (see below)
* Migrate the following packages' tests:
    * babel-helper-annotate-as-pure
    * babel-helper-module-imports
    * babel-helper-transform-fixture-test-runner
    * babel-highlight
    * babel-node
    * babel-plugin-transform-modules-commonjs
    * babel-preset-env-standalone
    * babel-preset-env
    * babel-preset-es2015
    * babel-preset-react
    * babel-standalone
    * babel-template
    * babel-traverse
    * babel-types
2018-03-24 16:22:10 +05:30
Daniel Tschinder
3e95830646
Migrate to jest (#7455) 2018-03-03 10:58:19 +01:00
Logan Smyth
278cd5e572
Preserve identifier location information when mapping this and arguments. (#7312) 2018-02-01 18:54:15 -08:00
Nicolò Ribaudo
8659e1a88c Remove old expected.{js,json} files (#7187) 2018-01-09 13:10:30 -06:00
Raja Sekar
0f42accb87 Renamed files 2018-01-09 15:36:42 +01:00
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