109 Commits

Author SHA1 Message Date
overlookmotel
792672ec60
Fix scope of computed method keys (#12812)
* Fix scope of computed method keys

* Test for nested computed keys

* Fix scope.rename with computed method keys

* Optional chaining tests
2021-02-19 02:36:34 +01:00
Huáng Jùnliàng
4462eeae6b
Clean up traverse scope (#12797) 2021-02-16 23:23:34 +01:00
Bogdan Savluk
d98418efbe
Convert @babel/traverse to TypeScript (#12488)
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
2021-01-24 01:33:09 +01:00
Nicolò Ribaudo
b5b95f81dc
Add @babel/traverse tests for re-exported bindings (#12429) 2020-12-06 19:33:21 +01:00
Nicolò Ribaudo
695abb8dfc
Set correct path.context un push/unshiftContainer (#12394) 2020-11-25 16:51:58 +01:00
Huáng Jùnliàng
eea3065039
Update pathCache in NodePath#_replaceWith (#12391)
* add tests on regression 12386

* fix: update cache on _replaceWith

* fix: pathCache in replaceWithMultiple could be nullish

* Update packages/babel-traverse/src/path/replacement.js

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>

* test: add replaceWith test to traverse

Co-authored-by: Brian Ng <bng412@gmail.com>
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
2020-11-24 15:07:20 -05:00
Nicolò Ribaudo
4f9ad5cc3a
Avoid infinite loops in type inference logic (#12390) 2020-11-23 17:03:01 +01:00
Nicolò Ribaudo
7d2a14b856
Initialize NodePath context when using getSibling (#12387) 2020-11-23 16:03:11 +01:00
Huáng Jùnliàng
6cb6f9f5ea
test: add tests about behaviour of replaceWithMultiple (#12309)
* test: add tests about behaviour of replaceWithMultiple

* add more tests
2020-11-04 14:46:53 -05:00
Nicolò Ribaudo
dd5a977048
Revert "Mark ThisExpression and Super as Purish" (#12307) 2020-11-04 11:50:46 +01:00
Nicolò Ribaudo
df908fc63b
Mark ThisExpression and Super as Purish (#12251)
* Mark `ThisExpression` as `Purish`

The other purish types are functions and literals, so I
guess it means "it doesn't have side effects"

* Super & tests

* Fix tests
2020-10-27 13:12:49 +01:00
Huáng Jùnliàng
e0b2bfb78f
fix: mark Pattern in CatchClause as scope (#12119) 2020-09-29 15:04:24 -04:00
Johan Holmerin
b9407d7660
Forward deopt node path in NodePath#evaludate (#11832)
* Forward deopt node path

* Move deopt evaluation tests

* Document evaluate deopt property
2020-08-20 16:20:19 -04:00
James Addison
9daa50e005
babel-traverse: prefer clearer, reduced-bias option naming (#11791)
* babel-traverse: prefer clearer, reduced-bias option naming

* Apply suggestions from code review

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
2020-07-29 16:41:20 -04:00
Wojciech Maj
1dd94e813e
Replace non-inclusive "whitelist" and "blacklist" terms with "allowlist" etc. (#11758) 2020-06-29 15:39:38 -04:00
Bogdan Savluk
4108524856
Update prettier to v2 (#11579)
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
2020-06-07 22:21:33 +02:00
任文龙
429840dc2b
scope.rename() missing identifier in VariableDeclarator (#11595) 2020-05-26 23:05:12 +02:00
Zen
83d365acb6
handle objectMethod in scope.isPure (#11482) 2020-04-25 18:34:52 +02:00
beraliv
6b8f6ab2de
transform-spread: create TS types (not Flow) when using TS (#11378)
*  add test fixture

*  add removeTypeDuplicates for typescript

*  add createTSUnionType for typescript

* 💊 fix ConditionalExpression for typescript

* 💊 fix ConditionalExpression

* 💊 fix added test case

*  add new line at the end of the file

* 💊 types.every(f) => f(types[0])

* 🔄 bug => foo

*  add TSBaseType

*  add conditions NOT to break backward compatibility
2020-04-15 21:47:28 +02:00
Mateusz Burzyński
70cc111b35
Fixed generateUid creating clashing ids after scope re-crawling (#11375) 2020-04-07 17:32:46 +02:00
Mateusz Burzyński
025e4ae44c
Fixed issue with programPath.scope.references not being regist… (#11323) 2020-03-24 16:27:32 +01:00
liuxingbaoyu
31b0506040
fix: @babel/traverse can't use path.remove() with noScope (#11136) 2020-02-14 12:19:32 -05:00
Huáng Jùnliàng
865d5155c2
Add eslint-plugin-jest (#11119)
* chore: add eslint-plugin-jest

* chore: update test sources

* chore: suppress preset-env debug log when linting
2020-02-11 00:11:32 +09:00
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