50 Commits

Author SHA1 Message Date
Chris West
bd4590e546
fix: cloneNode(deep, withoutLoc) handles absent comments (#12602)
This fragment (maybe all fragments?) throw during cloning, as
'comments' is unset here. Handle it being unset, by returning
undefined.
2021-01-12 20:40:23 -05:00
Niklas Mischkulnig
fdb5829a60
Use isIdentifierChar instead of regex for toIdentifier (#12575)
* Use isIdentifierChar instead of regex for toIdentifier

* Apply suggestions from code review

Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>

* Undo dep

* Update packages/babel-types/test/converters.js

* Add testcase starting with a number

* Add test for non-ascii starting character

Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
2020-12-31 11:22:46 -05:00
Nicolò Ribaudo
c139d1602b
Prepare codebase for inline Babel 8 breaking changes (#12440) 2020-12-04 21:30:40 +01:00
Nicolò Ribaudo
645fe637f2
Fix t.isReferenced() for named re-exports (#12395) 2020-11-25 19:39:45 +01:00
Nicolò Ribaudo
5743ad3923
[regression] Don't validate file.comments in @babel/types (#11752)
Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
2020-06-29 23:23:36 +02:00
William Law
cfaa70dcf4
skip following empty statements in toSequenceExpression (#11724)
* fix: statementlist behavior

* fixed prettier and babel-types/converter errors

* added check for first node

* remove node length check, only check if node is first

* add reset eLU if proceeding is non-empty

* fix failure for ci tests

* remove .expressions since sequence expression isn't produced

* changed test title
2020-06-25 13:38:01 -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
Taym Haddadi
286aaeadd9
Add cloneDeepWithoutLoc (#10680)
* feat: add cloneDeepWithoutLoc

* fix: sort functions alphabetically

* doc: add documentation for the withoutLoc parameter

* test: add a test for  shallow cloneWithoutLoc

* test: add loc object to node and fix test

* fix: set loc object on deeper node

* test: check loc on deeper node is null

* doc: adjust withoutLoc documentation

* fix: add withoutLoc param to deep clones

* fix: apply cloneIfNodeOrArray for leadingComments, innerComments and trailingComments

* test: add test for leadingComments, innerComments and trailingComments

* Cleanup PR

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
2020-03-16 23:07:01 +01:00
Jacob Williams
761563571c
Make isReferenced return false for method parameter name (#11089)
* Change isReferenced to return false for object/class method parameter names.

* use indexOf instead of for-of loop

* replace `.indexOf` check with `.includes` and assume `parent.params` exists

Co-Authored-By: Justin Ridgewell <justin@ridgewell.name>

* check .params within case block for ClassMethod/ClassPrivateMethod/ObjectMethod only

* add comment clarifying that case clause fall-through is intentional

Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
2020-02-06 00:59:16 +01:00
Michael J. Currie
66062c2a8c Template literal validation (#10492)
* add template literal validation

* avoid null/undefined error when validating

* simplify validation logic and fix tests

Co-authored-by: Michael J. Currie <michaeljcurrie136@gmail.com>
2019-09-26 19:58:36 +02:00
Even Alander
eb3767d58b Add a builder definition including name for tsTypeParameter (#10319) 2019-08-15 19:59:08 +02:00
Yuri Karadzhov
4506590557 Add static parameter to class property builder (#10248) 2019-07-25 09:55:03 +02:00
Tan Li Hau
ee68d6d1b0 add assertShape to validate templateElement (#10198)
* add assertShape to validate templateElement

* Update packages/babel-types/src/definitions/utils.js

Co-Authored-By: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>

* templateElement optional cooked
2019-07-15 01:03:50 +02:00
Nicolò Ribaudo
15dfce33df
Add placeholders support to @babel/types and @babel/generator (#9542) 2019-03-07 11:47:39 +01:00
Evan Henley
d72f3aa758 [plugin-transform-typescript] Strip type imports used in Enums and object types (#9605)
* fix: strip type imports used in Enums and object types

* chore: update failing snapshot

* docs: correct TSPropertySignature comment

* fix: enum value should be considered a reference

* chore: add tests for TSPropertySignature and TSEnumMember
2019-02-28 22:03:12 +01:00
Nicolò Ribaudo
5c8cc0d536
Mark FOO in "var { x: FOO }˝ as a binding, not as a reference (#9492) 2019-02-27 00:17:11 +01:00
Ilya Lesik
738060ebfa Fix support for Flow's DeclareClass type parameters (#9459) 2019-02-06 08:18:07 -06:00
David Laban
9803253363 flow type update: babel-types.isType(?string, string): boolean (#9275) 2019-01-07 08:53:01 -06:00
David Laban
3f9a1c08cc Add tests for babel-types.isType (#9243) 2018-12-27 12:49:34 +01:00
Daniel Tschinder
ca2918ab13
Test local version of babel/types 2018-12-05 13:34:36 -08:00
Daniel Tschinder
d915f31bcb Add tests for createTypeAnnotationBasedOnTypeof 2018-12-05 13:24:55 -08:00
Greg Bergé
4fcee1751a Fix cloneNode with typeAnnotation. (#8997)
Fixes #8996
2018-11-12 17:10:09 -08:00
Tim Kendrick
e9184ed05e [babel-types] Fix isNodesEquivalent() behavior for TemplateElements (#8165)
Fixes #8163

The `isNodesEquivalent()` algorithm incorrectly assumes that any object properties must themselves be AST nodes, which is not the case here, causing the error.
2018-07-06 08:45:25 -04:00
Peter Leonov
ab62a94399 make isReferenced() recognise ObjectTypeProperty (#8060)
fixes #8057
2018-05-31 00:07:56 +02:00
Logan Smyth
5e00c96368
Handle Infinity, -Infinity, NaN, and -0 in t.valueToNode(). (#8005)
| Q                        | A <!--(Can use an emoji 👍) -->
| ------------------------ | ---
| Fixed Issues?            | Fixes #8001
| Patch: Bug Fix?          | Y
| Major: Breaking Change?  | Not unless things were relying on a very specific AST structure as output
| Minor: New Feature?      |
| Tests Added + Pass?      | Yes
| Documentation PR         | <!-- If so, add `[skip ci]` to your commit message to skip CI -->
| Any Dependency Changes?  |
| License                  | MIT

The filed bug was for `-0`, but I also realize that `numericLiteral` also shouldn't be getting `-Infinity`/`Infinity` or `NaN` since those just get stringified with the JS-standard stringification logic which means we get a reference to `NaN` or `Infinity` identifiers, which could have been shadowed in a local scope and thus not be the right value. I've avoided that by generating `NaN` as `0/0` and the infinity values as `1/0` and `-1/0`.
2018-05-22 14:37:06 -07:00
Chaitanya Kumar Kamatham
daf0ca8680 Rename "babylon" to "@babel/parser" (#7937) 🎉 2018-05-19 00:03:05 -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
Nicolò Ribaudo
63ae923987 Add t.cloneNode and deprecate t.clone and t.cloneDeep (#7149) 2018-01-29 22:59:06 +01:00
Claudio Procida
ce420ba51c Fixes React isCompatTag validator accepting leading dash character (#7164) 2018-01-09 09:42:05 +01:00
Brian Ng
42f66782be
Improve error message in types assert (#7001) 2017-12-11 09:31:56 -06:00
Henry Zhu
691f90a774 Scoped: change test imports to @babel/ [skip ci] 2017-10-16 22:49:56 -04:00
Justin Ridgewell
c6edce115c Fix numeric-separator transform (#5968) 2017-07-20 11:35:53 -04:00
Brian Ng
e4b35f680d
Run prettier 2017-06-27 12:15:00 -05:00
Justin Ridgewell
5cc1cbf3bc Matches pattern cleanup (#5826)
* Extract duplicated function into babel-types

Also reimplements in a sane way.

* Add tests

* cleanup
2017-06-06 11:20:05 -04:00
Bo Lingen
8772e7fb89 Fix ObjectProperty patterns (#5762)
* Fix Object Property values to allow Patterns

* Add RestElement to allowed types

* add tests for nested pattern structures
2017-05-22 20:24:19 -04:00
Justin Ridgewell
58216f5022 Hoist toSequenceExpression's convert helper (#5693) 2017-05-19 17:35:05 -04:00
Daniel Tschinder
ae8728c146
Merge branch 'master' into 7.0 2017-03-19 14:21:00 +01:00
Diogo Franco
256fcbc58f Treat "await" as an invalid identifier (#4954)
It is valid (outside `async` functions) in the "script" parse goal, but always invalid in the "module" parse goal.

Fixes #4952.
2017-03-19 11:28:52 +09:00
Logan Smyth
39c862c195 Make only/ignore relative to cwd/config file and move only/ignore checking all to core. (#5487)
* Make only/ignore relative to cwd/config file and move only/ignore checking all to core.
2017-03-16 23:22:43 -07:00
Brian Ng
8a82cc060a Run new lint rules (#5413) 2017-03-04 10:46:01 -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
Sergey Rubanov
292c3ca206 Refactor test packages to use ES modules instead of CJS (#5138) 2017-01-16 11:25:04 -05:00
Henry Zhu
672adba9a1 enable prefer const (#5113) 2017-01-14 09:48:52 -05:00
Ryan Tsao
39d18679e1 Fix getBindingIdentifiers in babel-types (#5068)
* Added getBindingIdentifier tests

* Added failing test for getBindingIdentifiers

* Fix babel-types getBindingIdentifiers
2017-01-09 09:08:07 -05:00
Nikolai Tillmann
efefe828f9 Preserve null in babel-types' clone and deepClone. (#4853)
* Preserve null in babel-types' clone and deepClone.
* Also respect undefined when cloning.
* Updating last test to reflect original test case "[,0]"
2016-11-17 08:52:04 -05:00
Henry Zhu
8475b6ec02 fix lint 2016-11-15 14:51:26 -05:00
Henry Zhu
6a6ec8785b Start babel-types tests, add isNodesEquivalent (#3553) 2016-11-15 14:24:20 -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