Compare commits
245 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d896ce2b53 | ||
|
|
44d8a59361 | ||
|
|
344d35bbe9 | ||
|
|
fe71154626 | ||
|
|
65cbbc1ef8 | ||
|
|
d37c958637 | ||
|
|
9eb010da50 | ||
|
|
7e9029e337 | ||
|
|
00c3e3c8e0 | ||
|
|
7192546eb8 | ||
|
|
4c4c22a316 | ||
|
|
56044c7851 | ||
|
|
828169e611 | ||
|
|
1452e977a0 | ||
|
|
ede69eef7f | ||
|
|
03230eaa9c | ||
|
|
7dc157f9be | ||
|
|
854313a759 | ||
|
|
46ba5940c2 | ||
|
|
42c5d3fc4b | ||
|
|
d4e045ac24 | ||
|
|
8bc9f9a05f | ||
|
|
93e1b5e612 | ||
|
|
4f69699b71 | ||
|
|
f4f5ca2aaa | ||
|
|
8071dca9ad | ||
|
|
178f2d7949 | ||
|
|
65febdd13a | ||
|
|
f77c450cda | ||
|
|
f2af6c1170 | ||
|
|
43b83f8ed7 | ||
|
|
af88e63dff | ||
|
|
f6ee26c3da | ||
|
|
e8de6fa5d4 | ||
|
|
3ae5e79ec8 | ||
|
|
e9331aa0c0 | ||
|
|
ba4141934f | ||
|
|
96a7343142 | ||
|
|
a2e6d8e968 | ||
|
|
4ce37b7aca | ||
|
|
b92ad318f1 | ||
|
|
2d6231fd3d | ||
|
|
4e5e319d5b | ||
|
|
b66d921053 | ||
|
|
f12905b531 | ||
|
|
f216975378 | ||
|
|
3a3d5cbe9c | ||
|
|
10555c719e | ||
|
|
58768072ef | ||
|
|
455e003567 | ||
|
|
49f7bcf271 | ||
|
|
c2e41588aa | ||
|
|
a1eac37bd2 | ||
|
|
0370af58f1 | ||
|
|
8df0500f55 | ||
|
|
e4b8cfc768 | ||
|
|
a7757ec4d0 | ||
|
|
25a8db2a29 | ||
|
|
48fd387779 | ||
|
|
59c4bbb4ab | ||
|
|
2dc1c91955 | ||
|
|
ae154c86ed | ||
|
|
e9588061d7 | ||
|
|
0a88230ec4 | ||
|
|
a27b9b4299 | ||
|
|
aaec2cd51d | ||
|
|
34c9890f41 | ||
|
|
e8038863c3 | ||
|
|
694e3fd8cf | ||
|
|
40ae6568a4 | ||
|
|
4944e9e180 | ||
|
|
a24206eb96 | ||
|
|
d6b4ab75ee | ||
|
|
3e4b608a80 | ||
|
|
28319eb07e | ||
|
|
5889620a6a | ||
|
|
9764718c32 | ||
|
|
28b70e5910 | ||
|
|
4c2f8d9337 | ||
|
|
2cc0376756 | ||
|
|
8e051cae46 | ||
|
|
778a61a3c2 | ||
|
|
46e3f6df1f | ||
|
|
03022d169e | ||
|
|
9803253363 | ||
|
|
a55382e4ad | ||
|
|
b211b810d1 | ||
|
|
25e880d355 | ||
|
|
e43777bb5f | ||
|
|
efc60a1703 | ||
|
|
54f072991d | ||
|
|
a58893d1e3 | ||
|
|
865eb93c2d | ||
|
|
49f52bbcb3 | ||
|
|
9d1d0fe57a | ||
|
|
ea1c436ea1 | ||
|
|
3f9a1c08cc | ||
|
|
c586d4e8ca | ||
|
|
60ffe1d103 | ||
|
|
b5177ce290 | ||
|
|
d1aa665657 | ||
|
|
f130981546 | ||
|
|
bc347bab7a | ||
|
|
21228abfde | ||
|
|
e417437355 | ||
|
|
0bb720401b | ||
|
|
d35f2ad92b | ||
|
|
57759cb1a1 | ||
|
|
9e95da4eaa | ||
|
|
911c2d0bf4 | ||
|
|
116ca22def | ||
|
|
52fb884550 | ||
|
|
5cb38995c0 | ||
|
|
3c8e15dbc1 | ||
|
|
c1499b13ac | ||
|
|
7bcd62cfee | ||
|
|
47da5cf75a | ||
|
|
72471aff63 | ||
|
|
b9340bc597 | ||
|
|
731182eee4 | ||
|
|
f4eec5ca79 | ||
|
|
b60adce4cb | ||
|
|
66c4bc8f64 | ||
|
|
d2dc28ed2b | ||
|
|
0514a9f903 | ||
|
|
d1d3c823cc | ||
|
|
9b005dedfd | ||
|
|
4fdb71151f | ||
|
|
f611bb016b | ||
|
|
4dff205dc1 | ||
|
|
72fd2d192c | ||
|
|
35815832b5 | ||
|
|
9c45b8faf7 | ||
|
|
ca2918ab13 | ||
|
|
d915f31bcb | ||
|
|
4ca35ef8b9 | ||
|
|
4b73818c87 | ||
|
|
d305419da6 | ||
|
|
8b132c0889 | ||
|
|
b927fb2a7e | ||
|
|
282129ea66 | ||
|
|
fc5d49b6f6 | ||
|
|
6c2771c116 | ||
|
|
fdc869ce16 | ||
|
|
fa9df678ac | ||
|
|
3932830535 | ||
|
|
07eaa3c63f | ||
|
|
3530d11418 | ||
|
|
806e133473 | ||
|
|
2bf8dde782 | ||
|
|
4e28459a2f | ||
|
|
c4d6f6dcce | ||
|
|
0859535b62 | ||
|
|
6e39b58f8a | ||
|
|
559d649994 | ||
|
|
3fda01b185 | ||
|
|
4f2eacf615 | ||
|
|
0047ae84b3 | ||
|
|
2bb24f996f | ||
|
|
61f2aed5b0 | ||
|
|
9308c870f5 | ||
|
|
1b8d664bbe | ||
|
|
844dd33f3d | ||
|
|
856edbf95f | ||
|
|
100b38784d | ||
|
|
4cbd22a15f | ||
|
|
d2971a1959 | ||
|
|
4f16a12c03 | ||
|
|
e7f0c065cf | ||
|
|
70318c9413 | ||
|
|
6e84352b51 | ||
|
|
0eb9b2463d | ||
|
|
445b14148e | ||
|
|
61c1c77a28 | ||
|
|
5979b0669b | ||
|
|
a2afb974be | ||
|
|
c11cdcb6d8 | ||
|
|
8c7d4b55c9 | ||
|
|
88696601e1 | ||
|
|
20a9d71016 | ||
|
|
1af57e6f71 | ||
|
|
4e1d6e7ff4 | ||
|
|
efb71ea12b | ||
|
|
cbbb3c7962 | ||
|
|
4fcee1751a | ||
|
|
efa571a42c | ||
|
|
bf8c4785f2 | ||
|
|
4f206b2416 | ||
|
|
504b331da4 | ||
|
|
74f969b603 | ||
|
|
4dfd801887 | ||
|
|
62233ed7c9 | ||
|
|
7b54ab620b | ||
|
|
343f776ca5 | ||
|
|
756ded4d64 | ||
|
|
b706e34fc8 | ||
|
|
5d5cd8612f | ||
|
|
afe67a7035 | ||
|
|
2fa1984635 | ||
|
|
2194842d11 | ||
|
|
e3b2c1afff | ||
|
|
b95cbc4a8e | ||
|
|
24c4901ff5 | ||
|
|
c125b1dd74 | ||
|
|
f216a7b06f | ||
|
|
c6d2f45cab | ||
|
|
1d4d760ffc | ||
|
|
a0e94ec24d | ||
|
|
b593af17a9 | ||
|
|
4521204ea0 | ||
|
|
d35563ee1a | ||
|
|
38397ce11f | ||
|
|
cd81b079ee | ||
|
|
e85faec47d | ||
|
|
0d9e77f559 | ||
|
|
c82750a48a | ||
|
|
de80aefece | ||
|
|
e4929e11f6 | ||
|
|
d942d47e10 | ||
|
|
84e7884d9c | ||
|
|
9d0dcedb2b | ||
|
|
b576bf4b41 | ||
|
|
e541d6031a | ||
|
|
5fa3628506 | ||
|
|
f71e4660d4 | ||
|
|
929567523c | ||
|
|
122906d525 | ||
|
|
25d01460fd | ||
|
|
ba5642d4ee | ||
|
|
15e6d844ae | ||
|
|
d1cae2dec2 | ||
|
|
11aee13ff2 | ||
|
|
39e7ee6e65 | ||
|
|
094ef31c01 | ||
|
|
afd0638b74 | ||
|
|
6e41edb90f | ||
|
|
7931f4c241 | ||
|
|
b847d40842 | ||
|
|
e91a02cc49 | ||
|
|
cc526940ee | ||
|
|
7188820151 | ||
|
|
00845709ce | ||
|
|
b50fdc191e | ||
|
|
ef0f723fc5 | ||
|
|
fbf62b4830 |
@@ -34,7 +34,7 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
working_directory: ~/babel
|
working_directory: ~/babel
|
||||||
docker:
|
docker:
|
||||||
- image: circleci/node:10
|
- image: circleci/node:11
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- restore-cache: *restore-yarn-cache
|
- restore-cache: *restore-yarn-cache
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"root": true,
|
"root": true,
|
||||||
"extends": "babel",
|
"extends": "babel",
|
||||||
"plugins": ["local-rules", "prettier"],
|
"plugins": ["prettier", "@babel/development"],
|
||||||
"rules": {
|
"rules": {
|
||||||
"prettier/prettier": "error"
|
"prettier/prettier": "error"
|
||||||
},
|
},
|
||||||
@@ -12,8 +12,8 @@
|
|||||||
{
|
{
|
||||||
"files": ["packages/*/src/**/*.js", "codemods/*/src/**/*.js"],
|
"files": ["packages/*/src/**/*.js", "codemods/*/src/**/*.js"],
|
||||||
"rules": {
|
"rules": {
|
||||||
"local-rules/no-undefined-identifier": "error",
|
"@babel/development/no-undefined-identifier": "error",
|
||||||
"local-rules/no-deprecated-clone": "error"
|
"@babel/development/no-deprecated-clone": "error"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -26,6 +26,13 @@
|
|||||||
"env": {
|
"env": {
|
||||||
"jest": true
|
"jest": true
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"files": ["packages/babel-plugin-*/src/index.js"],
|
||||||
|
"excludedFiles": ["packages/babel-plugin-transform-regenerator/**/*.js"],
|
||||||
|
"rules": {
|
||||||
|
"@babel/development/plugin-name": "error"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
13
.flowconfig
13
.flowconfig
@@ -1,11 +1,10 @@
|
|||||||
[ignore]
|
[ignore]
|
||||||
.*/build/.*
|
<PROJECT_ROOT>/build/.*
|
||||||
.*/packages/.*/lib
|
<PROJECT_ROOT>/packages/.*/lib
|
||||||
.*/packages/.*/test
|
<PROJECT_ROOT>/packages/.*/test
|
||||||
.*/codemods/.*/lib
|
<PROJECT_ROOT>/codemods/.*/lib
|
||||||
.*/codemods/.*/test
|
<PROJECT_ROOT>/codemods/.*/test
|
||||||
.*/node_modules/conventional-changelog-core/
|
<PROJECT_ROOT>/node_modules/module-deps/
|
||||||
.*/node_modules/module-deps/
|
|
||||||
|
|
||||||
[include]
|
[include]
|
||||||
packages/*/src
|
packages/*/src
|
||||||
|
|||||||
9
.github/ISSUE_TEMPLATE/Bug_report.md
vendored
9
.github/ISSUE_TEMPLATE/Bug_report.md
vendored
@@ -1,6 +1,9 @@
|
|||||||
---
|
---
|
||||||
name: 🐛 Bug Report
|
name: "\U0001F41B Bug Report"
|
||||||
about: If something isn't working as expected 🤔.
|
about: "If something isn't working as expected \U0001F914."
|
||||||
|
title: ''
|
||||||
|
labels: 'i: bug, i: needs triage'
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -31,7 +34,7 @@ A clear and concise description of what you expected to happen (or code).
|
|||||||
- Babel version(s): [e.g. v6.0.0, v7.0.0-beta.34]
|
- Babel version(s): [e.g. v6.0.0, v7.0.0-beta.34]
|
||||||
- Node/npm version: [e.g. Node 8/npm 5]
|
- Node/npm version: [e.g. Node 8/npm 5]
|
||||||
- OS: [e.g. OSX 10.13.4, Windows 10]
|
- OS: [e.g. OSX 10.13.4, Windows 10]
|
||||||
- Monorepo [e.g. yes/no/Lerna]
|
- Monorepo: [e.g. yes/no/Lerna]
|
||||||
- How you are using Babel: [e.g. `cli`, `register`, `loader`]
|
- How you are using Babel: [e.g. `cli`, `register`, `loader`]
|
||||||
|
|
||||||
**Possible Solution**
|
**Possible Solution**
|
||||||
|
|||||||
7
.github/ISSUE_TEMPLATE/Feature_request.md
vendored
7
.github/ISSUE_TEMPLATE/Feature_request.md
vendored
@@ -1,6 +1,9 @@
|
|||||||
---
|
---
|
||||||
name: 🚀 Feature Request
|
name: "\U0001F680 Feature Request"
|
||||||
about: I have a suggestion (and may want to implement it 🙂)!
|
about: "I have a suggestion (and may want to implement it \U0001F642)!"
|
||||||
|
title: ''
|
||||||
|
labels: 'i: enhancement, i: needs triage'
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
10
.github/ISSUE_TEMPLATE/Regression-v7.md
vendored
10
.github/ISSUE_TEMPLATE/Regression-v7.md
vendored
@@ -1,12 +1,16 @@
|
|||||||
---
|
---
|
||||||
name: 💥 v7 Regression
|
name: "\U0001F4A5 v7 Regression"
|
||||||
about: Report an unexpected behavior in v7 from v6 (Check the upgrade guide first ✌️)
|
about: Report an unexpected behavior in v7 from v6 (Check the upgrade guide first
|
||||||
|
✌️)
|
||||||
|
title: ''
|
||||||
|
labels: 'i: bug, 7.x: regression, i: needs triage'
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
# v7 Regression
|
# v7 Regression
|
||||||
|
|
||||||
> First check out: https://new.babeljs.io/docs/en/next/v7-migration.html
|
> First check out: https://babeljs.io/docs/en/v7-migration
|
||||||
> Also a partial upgrade tool: https://github.com/babel/babel-upgrade
|
> Also a partial upgrade tool: https://github.com/babel/babel-upgrade
|
||||||
|
|
||||||
**Potential Commit/PR that introduced the regression**
|
**Potential Commit/PR that introduced the regression**
|
||||||
|
|||||||
7
.github/ISSUE_TEMPLATE/Support_question.md
vendored
7
.github/ISSUE_TEMPLATE/Support_question.md
vendored
@@ -1,6 +1,9 @@
|
|||||||
---
|
---
|
||||||
name: 🤗 Support Question
|
name: "\U0001F917 Support Question"
|
||||||
about: If you have a question 💬, please check out our Slack or StackOverflow!
|
about: "If you have a question \U0001F4AC, please check out our Slack or StackOverflow!"
|
||||||
|
title: ''
|
||||||
|
labels: 'i: question, i: needs triage'
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
8
.github/ISSUE_TEMPLATE/Support_us.md
vendored
8
.github/ISSUE_TEMPLATE/Support_us.md
vendored
@@ -1,6 +1,10 @@
|
|||||||
---
|
---
|
||||||
name: 🤝 Support us on Babel
|
name: "\U0001F91D Support us on Babel"
|
||||||
about: If you would like to support our efforts in maintaining this community-driven project 🙌!
|
about: "If you would like to support our efforts in maintaining this community-driven
|
||||||
|
project \U0001F64C!"
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
18
.github/actions/trigger-github-release/Dockerfile
vendored
Normal file
18
.github/actions/trigger-github-release/Dockerfile
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
FROM node:10
|
||||||
|
|
||||||
|
LABEL "name" = "trigger-github-release"
|
||||||
|
LABEL "version" = "0.0.1"
|
||||||
|
|
||||||
|
LABEL "com.github.actions.name" = "Trigger GitHub release"
|
||||||
|
LABEL "com.github.actions.description" = "Trigger a new GitHub release and generate the changelog using lerna-changelog."
|
||||||
|
LABEL "com.github.actions.icon" = "tag"
|
||||||
|
LABEL "com.github.actions.color" = "yellow"
|
||||||
|
|
||||||
|
ADD entrypoint.sh /action/entrypoint.sh
|
||||||
|
ADD package.json /action/package.json
|
||||||
|
ADD package-lock.json /action/package-lock.json
|
||||||
|
ADD release.js /action/release.js
|
||||||
|
|
||||||
|
RUN chmod +x /action/entrypoint.sh
|
||||||
|
|
||||||
|
ENTRYPOINT ["/action/entrypoint.sh"]
|
||||||
29
.github/actions/trigger-github-release/entrypoint.sh
vendored
Executable file
29
.github/actions/trigger-github-release/entrypoint.sh
vendored
Executable file
@@ -0,0 +1,29 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "INFO: Installing action dependencies..."
|
||||||
|
(cd /action; npm ci)
|
||||||
|
|
||||||
|
echo "INFO: Checking out current tag..."
|
||||||
|
git -c advice.detachedHead=false checkout $GITHUB_REF
|
||||||
|
|
||||||
|
echo "INFO: Getting tag info..."
|
||||||
|
current_tag=$(git describe --abbrev=0 --tags)
|
||||||
|
last_tag=$(git describe --abbrev=0 --tags HEAD^)
|
||||||
|
echo "INFO: New version is $current_tag; last version is $last_tag."
|
||||||
|
|
||||||
|
echo "INFO: Generating the changelog..."
|
||||||
|
|
||||||
|
# lerna-changelog expects the token to be provided as GITHUB_AUTH,
|
||||||
|
# but GitHub actions don't allow to predefine custom env vars prefixed with
|
||||||
|
# GITHUB_. We need to define it here.
|
||||||
|
changelog=$(
|
||||||
|
GITHUB_AUTH="$GITHUB_TOKEN" \
|
||||||
|
node /action/node_modules/.bin/lerna-changelog --tag-from $last_tag --tag-to $current_tag
|
||||||
|
)
|
||||||
|
|
||||||
|
echo "INFO: Publishing the new GitHub release..."
|
||||||
|
echo "$changelog" | node /action/release $current_tag
|
||||||
|
|
||||||
|
echo "INFO: Done! Don't forget to thank new contributors :)"
|
||||||
1415
.github/actions/trigger-github-release/package-lock.json
generated
vendored
Normal file
1415
.github/actions/trigger-github-release/package-lock.json
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
12
.github/actions/trigger-github-release/package.json
vendored
Normal file
12
.github/actions/trigger-github-release/package.json
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"private": true,
|
||||||
|
"name": "@internal/trigger-github-release",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"author": "Nicolò Ribaudo <nicolo.ribaudo@gmail.com>",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@octokit/rest": "^16.3.0",
|
||||||
|
"get-stdin": "^6.0.0",
|
||||||
|
"lerna-changelog": "^0.8.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
25
.github/actions/trigger-github-release/release.js
vendored
Normal file
25
.github/actions/trigger-github-release/release.js
vendored
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const [ /* node */, /* file */, tag ] = process.argv;
|
||||||
|
|
||||||
|
const getStdin = require("get-stdin");
|
||||||
|
const octokit = require("@octokit/rest")();
|
||||||
|
|
||||||
|
octokit.authenticate({
|
||||||
|
type: "token",
|
||||||
|
token: process.env.GITHUB_TOKEN
|
||||||
|
});
|
||||||
|
|
||||||
|
const [ repoOwner, repoName ] = process.env.GITHUB_REPOSITORY.split("/");
|
||||||
|
|
||||||
|
getStdin()
|
||||||
|
.then(changelog => octokit.repos.createRelease({
|
||||||
|
owner: repoOwner,
|
||||||
|
repo: repoName,
|
||||||
|
tag_name: tag,
|
||||||
|
body: changelog,
|
||||||
|
}))
|
||||||
|
.catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
26
.github/main.workflow
vendored
Normal file
26
.github/main.workflow
vendored
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
workflow "Release" {
|
||||||
|
on = "push"
|
||||||
|
resolves = ["Trigger GitHub release"]
|
||||||
|
}
|
||||||
|
|
||||||
|
action "Trigger GitHub release" {
|
||||||
|
uses = "./.github/actions/trigger-github-release/"
|
||||||
|
secrets = ["GITHUB_TOKEN"]
|
||||||
|
|
||||||
|
# When GitHub Actions will support the "release" event for public
|
||||||
|
# repositories, we won't need these checks anymore.
|
||||||
|
needs = [
|
||||||
|
"Is version tag",
|
||||||
|
"On master branch",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
action "Is version tag" {
|
||||||
|
uses = "actions/bin/filter@master"
|
||||||
|
args = "tag v*"
|
||||||
|
}
|
||||||
|
|
||||||
|
action "On master branch" {
|
||||||
|
uses = "actions/bin/filter@master"
|
||||||
|
args = "branch master"
|
||||||
|
}
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,5 +1,6 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
/node_modules
|
/node_modules
|
||||||
|
/.github/actions/*/node_modules
|
||||||
/packages/*/node_modules
|
/packages/*/node_modules
|
||||||
/packages/*/LICENSE
|
/packages/*/LICENSE
|
||||||
!/packages/babel-parser/LICENSE
|
!/packages/babel-parser/LICENSE
|
||||||
@@ -15,6 +16,7 @@ coverage
|
|||||||
dist
|
dist
|
||||||
/.package.json
|
/.package.json
|
||||||
package-lock.json
|
package-lock.json
|
||||||
|
!/.github/actions/*/package-lock.json
|
||||||
|
|
||||||
/packages/babel-runtime/helpers/*.js
|
/packages/babel-runtime/helpers/*.js
|
||||||
!/packages/babel-runtime/helpers/toArray.js
|
!/packages/babel-runtime/helpers/toArray.js
|
||||||
|
|||||||
@@ -1,2 +1,5 @@
|
|||||||
package.json
|
package.json
|
||||||
packages/babel-preset-env/data
|
packages/babel-preset-env/data
|
||||||
|
packages/*/test/fixtures/**/input.*
|
||||||
|
packages/*/test/fixtures/**/exec.*
|
||||||
|
packages/*/test/fixtures/**/output.*
|
||||||
|
|||||||
24
.travis.yml
24
.travis.yml
@@ -1,14 +1,11 @@
|
|||||||
git:
|
git:
|
||||||
depth: 10
|
depth: 5
|
||||||
sudo: false
|
|
||||||
language: node_js
|
language: node_js
|
||||||
cache:
|
cache:
|
||||||
yarn: true
|
yarn: true
|
||||||
directories:
|
|
||||||
- node_modules
|
|
||||||
node_js:
|
node_js:
|
||||||
# We test the latest version on circleci
|
# We test the latest version on circleci
|
||||||
- '9'
|
- '10'
|
||||||
- '8'
|
- '8'
|
||||||
- '6'
|
- '6'
|
||||||
|
|
||||||
@@ -20,17 +17,20 @@ env:
|
|||||||
before_install:
|
before_install:
|
||||||
- curl -o- -L https://yarnpkg.com/install.sh | bash
|
- curl -o- -L https://yarnpkg.com/install.sh | bash
|
||||||
|
|
||||||
install: yarn --ignore-engines
|
install:
|
||||||
|
# the `make test-ci` script runs this command already
|
||||||
|
- if [ "$JOB" != "test" ] && [ "$JOB" != "lint" ]; then yarn install; fi
|
||||||
|
- if [ "$JOB" = "lint" ]; then make bootstrap; fi
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- 'if [ "$JOB" = "babel-parser-flow-tests" ]; then make bootstrap-flow; fi'
|
- if [ "$JOB" = "babel-parser-flow-tests" ]; then make bootstrap-flow; fi
|
||||||
- 'if [ "$JOB" = "babel-parser-test262-tests" ]; then make bootstrap-test262; fi'
|
- if [ "$JOB" = "babel-parser-test262-tests" ]; then make bootstrap-test262; fi
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- 'if [ "$JOB" = "test" ]; then make test-ci; fi'
|
- if [ "$JOB" = "test" ]; then make test-ci; fi
|
||||||
- 'if [ "$JOB" = "lint" ]; then make lint && make flow; fi'
|
- if [ "$JOB" = "lint" ]; then make lint && make flow; fi
|
||||||
- 'if [ "$JOB" = "babel-parser-flow-tests" ]; then make test-flow-ci; fi'
|
- if [ "$JOB" = "babel-parser-flow-tests" ]; then make test-flow-ci; fi
|
||||||
- 'if [ "$JOB" = "babel-parser-test262-tests" ]; then make test-test262-ci; fi'
|
- if [ "$JOB" = "babel-parser-test262-tests" ]; then make test-test262-ci; fi
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
|
|||||||
160
CHANGELOG.md
160
CHANGELOG.md
@@ -15,6 +15,164 @@ See [CHANGELOG - v4](/.github/CHANGELOG-v4.md), [CHANGELOG - v5](/.github/CHANGE
|
|||||||
See [CHANGELOG - 6to5](/.github/CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
See [CHANGELOG - 6to5](/.github/CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
||||||
See [Babylon's CHANGELOG](packages/babylon/CHANGELOG.md) for the Babylon pre-7.0.0-beta.29 version changelog.
|
See [Babylon's CHANGELOG](packages/babylon/CHANGELOG.md) for the Babylon pre-7.0.0-beta.29 version changelog.
|
||||||
|
|
||||||
|
## v7.2.1 (2018-12-04)
|
||||||
|
|
||||||
|
This release fixes a regression introduced in v7.2.0 (https://github.com/babel/babel/issues/9120)
|
||||||
|
|
||||||
|
#### :bug: Bug Fix
|
||||||
|
* `babel-helper-create-class-features-plugin`
|
||||||
|
* [#9121](https://github.com/babel/babel/pull/9121) Don't use isClassPrivateMethod because it isn't supported in <7.2.0. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
|
||||||
|
|
||||||
|
## v7.2.0 (2018-12-03)
|
||||||
|
|
||||||
|
You can read more about this release at https://babeljs.io/blog/2018/12/03/7.2.0.
|
||||||
|
|
||||||
|
#### :rocket: New Feature
|
||||||
|
* `babel-parser`
|
||||||
|
* [#8289](https://github.com/babel/babel/pull/8289) Implement Smart Pipeline proposal in @babel/parser. ([@mAAdhaTTah](https://github.com/mAAdhaTTah))
|
||||||
|
* `babel-core`
|
||||||
|
* [#8986](https://github.com/babel/babel/pull/8986) Export @babel/parser#tokTypes in @babel/core. ([@kaicataldo](https://github.com/kaicataldo))
|
||||||
|
* `babel-node`
|
||||||
|
* [#9078](https://github.com/babel/babel/pull/9078) Pass `rootMode` from `@babel/node`.. ([@wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg))
|
||||||
|
* `babel-generator`, `babel-helpers`, `babel-plugin-class-features`, `babel-plugin-proposal-private-methods`, `babel-plugin-syntax-class-properties`, `babel-types`
|
||||||
|
* [#8654](https://github.com/babel/babel/pull/8654) Private class methods stage 3. ([@tim-mc](https://github.com/tim-mc))
|
||||||
|
* `babel-preset-env`
|
||||||
|
* [#9048](https://github.com/babel/babel/pull/9048) Update mappings for node 10 in preset-env. ([@existentialism](https://github.com/existentialism))
|
||||||
|
|
||||||
|
#### :bug: Bug Fix
|
||||||
|
* `babel-parser`
|
||||||
|
* [#9114](https://github.com/babel/babel/pull/9114) Parse non-octals with leading zeros in non strict mode correctly. ([@danez](https://github.com/danez))
|
||||||
|
* [#9074](https://github.com/babel/babel/pull/9074) Disallow await inside arrow functions. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
|
||||||
|
* [#9069](https://github.com/babel/babel/pull/9069) [flow] Allow type casts in array patterns inside arrow parameters. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
|
||||||
|
* [#9058](https://github.com/babel/babel/pull/9058) Fix compatibility between typescript and jsx plugins in interface declarations. ([@danez](https://github.com/danez))
|
||||||
|
* [#9055](https://github.com/babel/babel/pull/9055) Fix bug with parsing TS generic async arrow function. ([@existentialism](https://github.com/existentialism))
|
||||||
|
* [#9035](https://github.com/babel/babel/pull/9035) Fix parsing typescript function types with destructuring. ([@danez](https://github.com/danez))
|
||||||
|
* `babel-helper-fixtures`, `babel-parser`
|
||||||
|
* [#9113](https://github.com/babel/babel/pull/9113) Ignore empty fixture directories and fix fixtures in the parser. ([@danez](https://github.com/danez))
|
||||||
|
* `babel-preset-env`
|
||||||
|
* [#9091](https://github.com/babel/babel/pull/9091) Update mapping for regex unicode plugin in preset-env. ([@existentialism](https://github.com/existentialism))
|
||||||
|
* `babel-plugin-transform-destructuring`
|
||||||
|
* [#8916](https://github.com/babel/babel/pull/8916) Fix destructuring assignment in arrow functions without block. ([@RubenVerborgh](https://github.com/RubenVerborgh))
|
||||||
|
* `babel-plugin-proposal-optional-chaining`
|
||||||
|
* [#9073](https://github.com/babel/babel/pull/9073) Microbouji patch/8136. ([@jridgewell](https://github.com/jridgewell))
|
||||||
|
* `babel-core`, `babel-helper-wrap-function`, `babel-plugin-proposal-async-generator-functions`, `babel-plugin-proposal-function-sent`, `babel-plugin-transform-async-to-generator`, `babel-plugin-transform-classes`
|
||||||
|
* [#9039](https://github.com/babel/babel/pull/9039) Fix recursive async function expressions. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
|
||||||
|
* `babel-core`
|
||||||
|
* [#9034](https://github.com/babel/babel/pull/9034) Normalize presets before merging config with others.. ([@loganfsmyth](https://github.com/loganfsmyth))
|
||||||
|
|
||||||
|
#### :nail_care: Polish
|
||||||
|
* `babel-generator`
|
||||||
|
* [#9089](https://github.com/babel/babel/pull/9089) Remove unused variable. ([@Gcaufy](https://github.com/Gcaufy))
|
||||||
|
* `babel-node`
|
||||||
|
* [#9079](https://github.com/babel/babel/pull/9079) Move `fs-readdir-recursive` and `output-file-sync` to `devDependencies` for `@babel/node`.. ([@wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg))
|
||||||
|
* `babel-parser`
|
||||||
|
* [#9046](https://github.com/babel/babel/pull/9046) a better error message for disallowed trailing commas/additional parameters after rest elements in function params. ([@morozRed](https://github.com/morozRed))
|
||||||
|
* `babel-*`
|
||||||
|
* [#8769](https://github.com/babel/babel/pull/8769) Add plugins name. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
|
||||||
|
|
||||||
|
#### :house: Internal
|
||||||
|
* `babel-helper-create-class-features-plugin`, `babel-plugin-proposal-class-properties`, `babel-plugin-proposal-private-methods`
|
||||||
|
* [#9083](https://github.com/babel/babel/pull/9083) Make @babel/plugin-class-features a normal helper package. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
|
||||||
|
* Other
|
||||||
|
* [#9096](https://github.com/babel/babel/pull/9096) Add node 11 to CI and remove node 9. ([@danez](https://github.com/danez))
|
||||||
|
* [#9094](https://github.com/babel/babel/pull/9094) Skip minifying standalone in non-publish runs. ([@danez](https://github.com/danez))
|
||||||
|
* `babel-types`
|
||||||
|
* [#9093](https://github.com/babel/babel/pull/9093) Fix warning when using prettier in code generators. ([@danez](https://github.com/danez))
|
||||||
|
* `babel-generator`
|
||||||
|
* [#9089](https://github.com/babel/babel/pull/9089) Remove unused variable. ([@Gcaufy](https://github.com/Gcaufy))
|
||||||
|
|
||||||
|
## v7.1.6 (2018-11-13)
|
||||||
|
|
||||||
|
#### :bug: Bug Fix
|
||||||
|
* `babel-generator`
|
||||||
|
* [#9003](https://github.com/babel/babel/pull/9003) Fix retainLines regression for arrow functions. ([@loganfsmyth](https://github.com/loganfsmyth))
|
||||||
|
* `babel-types`
|
||||||
|
* [#8997](https://github.com/babel/babel/pull/8997) Fix cloneNode with typeAnnotation.. ([@neoziro](https://github.com/neoziro))
|
||||||
|
* `babel-plugin-transform-flow-strip-types`, `babel-plugin-transform-react-jsx`
|
||||||
|
* [#8701](https://github.com/babel/babel/pull/8701) Fix "TypeError: comments is not iterable". ([@AlicanC](https://github.com/AlicanC))
|
||||||
|
* `babel-core`
|
||||||
|
* [#9004](https://github.com/babel/babel/pull/9004) Fix browser files to have the same API as the nodejs ones. ([@danez](https://github.com/danez))
|
||||||
|
* Other
|
||||||
|
* [#9007](https://github.com/babel/babel/pull/9007) [Types] fix generated TS/Flow comment types. ([@ljqx](https://github.com/ljqx))
|
||||||
|
* `babel-preset-env`
|
||||||
|
* [#8555](https://github.com/babel/babel/pull/8555) preset-env: fix `opera` from `esmodules` target and Browserslist not used. ([@ylemkimon](https://github.com/ylemkimon))
|
||||||
|
* `babel-plugin-proposal-decorators`, `babel-traverse`
|
||||||
|
* [#8970](https://github.com/babel/babel/pull/8970) [decorators] Correctly insert `_initialize(this)` after `super()`.. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
|
||||||
|
* `babel-parser`
|
||||||
|
* [#8972](https://github.com/babel/babel/pull/8972) Fix several edge cases with context expression state. ([@danez](https://github.com/danez))
|
||||||
|
|
||||||
|
#### :nail_care: Polish
|
||||||
|
* `babel-parser`
|
||||||
|
* [#8984](https://github.com/babel/babel/pull/8984) Rename primitive types to reserved types. ([@danez](https://github.com/danez))
|
||||||
|
|
||||||
|
#### :house: Internal
|
||||||
|
* [#8982](https://github.com/babel/babel/pull/8982) fix publish command [skip ci]. ([@hzoo](https://github.com/hzoo))
|
||||||
|
* [#8988](https://github.com/babel/babel/pull/8988) Remove definition of micromatch which was removed.. ([@danez](https://github.com/danez))
|
||||||
|
|
||||||
|
## v7.1.5 (2018-11-06)
|
||||||
|
|
||||||
|
#### :eyeglasses: Spec Compliancy
|
||||||
|
* `babel-parser`, `babylon`
|
||||||
|
* [#7727](https://github.com/babel/babel/pull/7727) Fix await in function name and parameters. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
|
||||||
|
|
||||||
|
#### :rocket: New Feature
|
||||||
|
* `babel-parser`
|
||||||
|
* [#8828](https://github.com/babel/babel/pull/8828) Typescript: Validate tuple type element positions. ([@Retsam](https://github.com/Retsam))
|
||||||
|
* [#8883](https://github.com/babel/babel/pull/8883) [flow] Add support for parsing `_` as implicit instantiation in call/new. ([@jbrown215](https://github.com/jbrown215))
|
||||||
|
* `babel-core`, `babel-generator`, `babel-parser`, `babel-plugin-syntax-typescript`, `babel-traverse`
|
||||||
|
* [#8448](https://github.com/babel/babel/pull/8448) Remove Babylon plugins for features already merged to the ECMAScript spec. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
|
||||||
|
* `babel-parser`, `babel-types`
|
||||||
|
* [#8884](https://github.com/babel/babel/pull/8884) [flow] Explicit inexact objects with `...`. ([@jbrown215](https://github.com/jbrown215))
|
||||||
|
* `babel-preset-env`
|
||||||
|
* [#8898](https://github.com/babel/babel/pull/8898) Update preset-env data. ([@existentialism](https://github.com/existentialism))
|
||||||
|
|
||||||
|
#### :bug: Bug Fix
|
||||||
|
* `babel-parser`
|
||||||
|
* [#8956](https://github.com/babel/babel/pull/8956) Do not allow TypeCastExpressions w/o parens . ([@danez](https://github.com/danez))
|
||||||
|
* [#8954](https://github.com/babel/babel/pull/8954) Allow function types in type params within arrow return types. ([@danez](https://github.com/danez))
|
||||||
|
* [#8866](https://github.com/babel/babel/pull/8866) Closes [#8865](https://github.com/babel/babel/issues/8865). ([@byronluk](https://github.com/byronluk))
|
||||||
|
* `babel-core`
|
||||||
|
* [#8910](https://github.com/babel/babel/pull/8910) Resolve babel.config.js 'babelrcRoots' values relative to the config file.. ([@loganfsmyth](https://github.com/loganfsmyth))
|
||||||
|
* [#8950](https://github.com/babel/babel/pull/8950) Fix message when plugin of a wrong type is passed. ([@everdimension](https://github.com/everdimension))
|
||||||
|
* `babel-plugin-transform-block-scoping`
|
||||||
|
* [#8937](https://github.com/babel/babel/pull/8937) rename colliding let bindings with for loop init. ([@byronluk](https://github.com/byronluk))
|
||||||
|
* [#8914](https://github.com/babel/babel/pull/8914) Treat break inside block inside loop. ([@thiagoarrais](https://github.com/thiagoarrais))
|
||||||
|
* `babel-preset-env`
|
||||||
|
* [#8926](https://github.com/babel/babel/pull/8926) preset-env: Edge support for arrow param destructuring. ([@benmosher](https://github.com/benmosher))
|
||||||
|
* `babel-generator`
|
||||||
|
* [#8868](https://github.com/babel/babel/pull/8868) fix single-arg async arrows when retainLines=true. ([@ryanwmarsh](https://github.com/ryanwmarsh))
|
||||||
|
* `babel-traverse`
|
||||||
|
* [#8880](https://github.com/babel/babel/pull/8880) fix: Expression x === 'y' && '' should not evaluate to undefined.. ([@Cyp](https://github.com/Cyp))
|
||||||
|
|
||||||
|
#### :nail_care: Polish
|
||||||
|
* [#8873](https://github.com/babel/babel/pull/8873) fixed an extra word. ([@vvyomjjain](https://github.com/vvyomjjain))
|
||||||
|
|
||||||
|
## v7.1.4 (2018-10-11)
|
||||||
|
|
||||||
|
Just re-published `@babel/traverse` without `**` so that it works in Node 6.
|
||||||
|
|
||||||
|
## v7.1.3 (2018-10-11)
|
||||||
|
|
||||||
|
#### :bug: Bug Fix
|
||||||
|
* `babel-generator`, `babel-parser`, `babel-plugin-transform-typescript`, `babel-types`
|
||||||
|
* [#8720](https://github.com/babel/babel/pull/8720) Typescript - Tuple elements can be optional. ([@Retsam](https://github.com/Retsam))
|
||||||
|
* `babel-traverse`
|
||||||
|
* [#8833](https://github.com/babel/babel/pull/8833) Insertafter jsx fix. ([@kevintab95](https://github.com/kevintab95))
|
||||||
|
* `babel-parser`
|
||||||
|
* [#8830](https://github.com/babel/babel/pull/8830) Correct handling of newline after async with paren-less arrow func. ([@Retsam](https://github.com/Retsam))
|
||||||
|
* [#8756](https://github.com/babel/babel/pull/8756) class private methods and properties: should not allow spaces between # and identifier. ([@macabeus](https://github.com/macabeus))
|
||||||
|
* [#8804](https://github.com/babel/babel/pull/8804) Fix parsing of slash after class expression. ([@existentialism](https://github.com/existentialism))
|
||||||
|
* [#8767](https://github.com/babel/babel/pull/8767) [decorators] [typescript] Parse type parameters. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
|
||||||
|
* [#8792](https://github.com/babel/babel/pull/8792) Fix perf issue in typescript parser plugin. ([@matthewrobertson](https://github.com/matthewrobertson))
|
||||||
|
* `babel-generator`, `babel-parser`, `babel-plugin-transform-typescript`, `babel-types`
|
||||||
|
* [#8805](https://github.com/babel/babel/pull/8805) Typescript - Tuples can include rest elements. ([@Retsam](https://github.com/Retsam))
|
||||||
|
* `babel-types`
|
||||||
|
* [#8791](https://github.com/babel/babel/pull/8791) types: allow jsxEmptyExpression inside jsxExpressionContainer. ([@tvooo](https://github.com/tvooo))
|
||||||
|
* `babel-plugin-transform-modules-systemjs`
|
||||||
|
* [#8820](https://github.com/babel/babel/pull/8820) System module format - fixes function hoisting failure case. ([@guybedford](https://github.com/guybedford))
|
||||||
|
* `babel-plugin-transform-destructuring`
|
||||||
|
* [#8793](https://github.com/babel/babel/pull/8793) Ensure destructuring's computed key handling matches object-rest-spread. ([@existentialism](https://github.com/existentialism))
|
||||||
|
|
||||||
## 7.1.2 (2018-09-28)
|
## 7.1.2 (2018-09-28)
|
||||||
|
|
||||||
Same as v7.1.1, except compiled against Node 6 instead of Node 8 by accident (e.g had `async functions`).
|
Same as v7.1.1, except compiled against Node 6 instead of Node 8 by accident (e.g had `async functions`).
|
||||||
@@ -2542,7 +2700,7 @@ Also started Babel to compile itself with Babel 7! (We'll be working on making i
|
|||||||
|
|
||||||
#### :nail_care: Polish
|
#### :nail_care: Polish
|
||||||
* `babel-register`
|
* `babel-register`
|
||||||
* [#5411](https://github.com/babel/babel/pull/5411) Seperate version env cache files. ([@pwmckenna](https://github.com/pwmckenna))
|
* [#5411](https://github.com/babel/babel/pull/5411) Separate version env cache files. ([@pwmckenna](https://github.com/pwmckenna))
|
||||||
|
|
||||||
#### :memo: Documentation
|
#### :memo: Documentation
|
||||||
* `babel-plugin-transform-runtime`
|
* `babel-plugin-transform-runtime`
|
||||||
|
|||||||
@@ -310,7 +310,7 @@ Note that the code shown in Chrome DevTools is compiled code and therefore diffe
|
|||||||
- Create a new issue that describes the proposal (ex: [#538](https://github.com/babel/babylon/issues/538)). Include any relevant information like proposal repo/author, examples, parsing approaches, meeting notes, presentation slides, and more.
|
- Create a new issue that describes the proposal (ex: [#538](https://github.com/babel/babylon/issues/538)). Include any relevant information like proposal repo/author, examples, parsing approaches, meeting notes, presentation slides, and more.
|
||||||
- The pull request should include:
|
- The pull request should include:
|
||||||
- [ ] An update to the [plugins](https://github.com/babel/babel/tree/master/packages/babel-parser#plugins) part of the readme. Add a new entry to that list for the new plugin flag (and link to the proposal)
|
- [ ] An update to the [plugins](https://github.com/babel/babel/tree/master/packages/babel-parser#plugins) part of the readme. Add a new entry to that list for the new plugin flag (and link to the proposal)
|
||||||
- [ ] If any new nodes or modifications need to be added to the AST, update [ast/spec.md](https://github.com/babel/babel/bloc/master/packages/babel-parser/ast/spec.md)
|
- [ ] If any new nodes or modifications need to be added to the AST, update [ast/spec.md](https://github.com/babel/babel/blob/master/packages/babel-parser/ast/spec.md)
|
||||||
- [ ] Make sure you use the `this.hasPlugin("plugin-name-here")` check in the babel parser so that your new plugin code only runs when that flag is turned on (not default behavior)
|
- [ ] Make sure you use the `this.hasPlugin("plugin-name-here")` check in the babel parser so that your new plugin code only runs when that flag is turned on (not default behavior)
|
||||||
- [ ] Add failing/passing tests according to spec behavior
|
- [ ] Add failing/passing tests according to spec behavior
|
||||||
- Start working about the Babel transform itself!
|
- Start working about the Babel transform itself!
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const chalk = require("chalk");
|
|||||||
const newer = require("gulp-newer");
|
const newer = require("gulp-newer");
|
||||||
const babel = require("gulp-babel");
|
const babel = require("gulp-babel");
|
||||||
const gulpWatch = require("gulp-watch");
|
const gulpWatch = require("gulp-watch");
|
||||||
const gutil = require("gulp-util");
|
const fancyLog = require("fancy-log");
|
||||||
const filter = require("gulp-filter");
|
const filter = require("gulp-filter");
|
||||||
const gulp = require("gulp");
|
const gulp = require("gulp");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
@@ -38,7 +38,7 @@ function getIndexFromPackage(name) {
|
|||||||
|
|
||||||
function compilationLogger(rollup) {
|
function compilationLogger(rollup) {
|
||||||
return through.obj(function(file, enc, callback) {
|
return through.obj(function(file, enc, callback) {
|
||||||
gutil.log(
|
fancyLog(
|
||||||
`Compiling '${chalk.cyan(file.relative)}'${
|
`Compiling '${chalk.cyan(file.relative)}'${
|
||||||
rollup ? " with rollup " : ""
|
rollup ? " with rollup " : ""
|
||||||
}...`
|
}...`
|
||||||
@@ -50,7 +50,7 @@ function compilationLogger(rollup) {
|
|||||||
function errorsLogger() {
|
function errorsLogger() {
|
||||||
return plumber({
|
return plumber({
|
||||||
errorHandler(err) {
|
errorHandler(err) {
|
||||||
gutil.log(err.stack);
|
fancyLog(err.stack);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2014-2018 Sebastian McKenzie and other contributors
|
Copyright (c) 2014-present Sebastian McKenzie and other contributors
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
a copy of this software and associated documentation files (the
|
a copy of this software and associated documentation files (the
|
||||||
|
|||||||
24
Makefile
24
Makefile
@@ -1,6 +1,6 @@
|
|||||||
MAKEFLAGS = -j1
|
MAKEFLAGS = -j1
|
||||||
FLOW_COMMIT = bea8b83f50f597454941d2a7ecef6e93a881e576
|
FLOW_COMMIT = 2ac56861e3ceff9ca406ae586fbafb3480c6c0b7
|
||||||
TEST262_COMMIT = 06c2f019019cf7850923de4d56828e6dfd9212b8
|
TEST262_COMMIT = 4f1155c566a222238fd86f179c6635ecb4c289bb
|
||||||
|
|
||||||
# Fix color output until TravisCI fixes https://github.com/travis-ci/travis-ci/issues/7967
|
# Fix color output until TravisCI fixes https://github.com/travis-ci/travis-ci/issues/7967
|
||||||
export FORCE_COLOR = true
|
export FORCE_COLOR = true
|
||||||
@@ -15,8 +15,8 @@ build: clean clean-lib
|
|||||||
# call build again as the generated files might need to be compiled again.
|
# call build again as the generated files might need to be compiled again.
|
||||||
./node_modules/.bin/gulp build
|
./node_modules/.bin/gulp build
|
||||||
# generate flow and typescript typings
|
# generate flow and typescript typings
|
||||||
node scripts/generators/flow.js > ./packages/babel-types/lib/index.js.flow
|
node packages/babel-types/scripts/generators/flow.js > ./packages/babel-types/lib/index.js.flow
|
||||||
node scripts/generators/typescript.js > ./packages/babel-types/lib/index.d.ts
|
node packages/babel-types/scripts/generators/typescript.js > ./packages/babel-types/lib/index.d.ts
|
||||||
ifneq ("$(BABEL_COVERAGE)", "true")
|
ifneq ("$(BABEL_COVERAGE)", "true")
|
||||||
make build-standalone
|
make build-standalone
|
||||||
make build-preset-env-standalone
|
make build-preset-env-standalone
|
||||||
@@ -28,6 +28,12 @@ build-standalone:
|
|||||||
build-preset-env-standalone:
|
build-preset-env-standalone:
|
||||||
./node_modules/.bin/gulp build-babel-preset-env-standalone
|
./node_modules/.bin/gulp build-babel-preset-env-standalone
|
||||||
|
|
||||||
|
prepublish-build-standalone:
|
||||||
|
BABEL_ENV=production IS_PUBLISH=true ./node_modules/.bin/gulp build-babel-standalone
|
||||||
|
|
||||||
|
prepublish-build-preset-env-standalone:
|
||||||
|
BABEL_ENV=production IS_PUBLISH=true ./node_modules/.bin/gulp build-babel-preset-env-standalone
|
||||||
|
|
||||||
build-dist: build
|
build-dist: build
|
||||||
cd packages/babel-polyfill; \
|
cd packages/babel-polyfill; \
|
||||||
scripts/build-dist.sh
|
scripts/build-dist.sh
|
||||||
@@ -40,7 +46,8 @@ watch: clean clean-lib
|
|||||||
# development too.
|
# development too.
|
||||||
BABEL_ENV=development ./node_modules/.bin/gulp build-no-bundle
|
BABEL_ENV=development ./node_modules/.bin/gulp build-no-bundle
|
||||||
node ./packages/babel-types/scripts/generateTypeHelpers.js
|
node ./packages/babel-types/scripts/generateTypeHelpers.js
|
||||||
node scripts/generators/flow.js > ./packages/babel-types/lib/index.js.flow
|
node packages/babel-types/scripts/generators/flow.js > ./packages/babel-types/lib/index.js.flow
|
||||||
|
node packages/babel-types/scripts/generators/typescript.js > ./packages/babel-types/lib/index.d.ts
|
||||||
BABEL_ENV=development ./node_modules/.bin/gulp watch
|
BABEL_ENV=development ./node_modules/.bin/gulp watch
|
||||||
|
|
||||||
flow:
|
flow:
|
||||||
@@ -82,7 +89,7 @@ test-ci-coverage:
|
|||||||
bootstrap-flow:
|
bootstrap-flow:
|
||||||
rm -rf ./build/flow
|
rm -rf ./build/flow
|
||||||
mkdir -p ./build
|
mkdir -p ./build
|
||||||
git clone --branch=master --single-branch --shallow-since=2017-01-01 https://github.com/facebook/flow.git ./build/flow
|
git clone --branch=master --single-branch --shallow-since=2018-11-01 https://github.com/facebook/flow.git ./build/flow
|
||||||
cd build/flow && git checkout $(FLOW_COMMIT)
|
cd build/flow && git checkout $(FLOW_COMMIT)
|
||||||
|
|
||||||
test-flow:
|
test-flow:
|
||||||
@@ -96,7 +103,7 @@ test-flow-update-whitelist:
|
|||||||
bootstrap-test262:
|
bootstrap-test262:
|
||||||
rm -rf ./build/test262
|
rm -rf ./build/test262
|
||||||
mkdir -p ./build
|
mkdir -p ./build
|
||||||
git clone --branch=master --single-branch --shallow-since=2017-01-01 https://github.com/tc39/test262.git ./build/test262
|
git clone --branch=master --single-branch --shallow-since=2010-01-10 https://github.com/tc39/test262.git ./build/test262
|
||||||
cd build/test262 && git checkout $(TEST262_COMMIT)
|
cd build/test262 && git checkout $(TEST262_COMMIT)
|
||||||
|
|
||||||
test-test262:
|
test-test262:
|
||||||
@@ -124,8 +131,7 @@ prepublish:
|
|||||||
make test
|
make test
|
||||||
|
|
||||||
publish: prepublish
|
publish: prepublish
|
||||||
# --only-explicit-updates
|
./node_modules/.bin/lerna publish --force-publish="@babel/runtime,@babel/runtime-corejs2,@babel/standalone,@babel/preset-env-standalone" --require-scripts
|
||||||
./node_modules/.bin/lerna publish
|
|
||||||
make clean
|
make clean
|
||||||
|
|
||||||
bootstrap: clean-all
|
bootstrap: clean-all
|
||||||
|
|||||||
34
README.md
34
README.md
@@ -8,12 +8,16 @@
|
|||||||
The compiler for writing next generation JavaScript.
|
The compiler for writing next generation JavaScript.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://www.npmjs.com/package/@babel/core"><img alt="v7 npm Downloads" src="https://img.shields.io/npm/dm/@babel/core.svg?maxAge=43200&label=v7%20downloads"></a>
|
||||||
|
<a href="https://www.npmjs.com/package/babel-core"><img alt="v6 npm Downloads" src="https://img.shields.io/npm/dm/babel-core.svg?maxAge=43200&label=v6%20downloads"></a>
|
||||||
|
</p>
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://travis-ci.org/babel/babel"><img alt="Travis Status" src="https://img.shields.io/travis/babel/babel/master.svg?label=travis&maxAge=43200"></a>
|
<a href="https://travis-ci.org/babel/babel"><img alt="Travis Status" src="https://img.shields.io/travis/babel/babel/master.svg?label=travis&maxAge=43200"></a>
|
||||||
<a href="https://circleci.com/gh/babel/babel"><img alt="CircleCI Status" src="https://img.shields.io/circleci/project/github/babel/babel/master.svg?label=circle&maxAge=43200"></a>
|
<a href="https://circleci.com/gh/babel/babel"><img alt="CircleCI Status" src="https://img.shields.io/circleci/project/github/babel/babel/master.svg?label=circle&maxAge=43200"></a>
|
||||||
<a href="https://codecov.io/github/babel/babel"><img alt="Coverage Status" src="https://img.shields.io/codecov/c/github/babel/babel/master.svg?maxAge=43200"></a>
|
<a href="https://codecov.io/github/babel/babel"><img alt="Coverage Status" src="https://img.shields.io/codecov/c/github/babel/babel/master.svg?maxAge=43200"></a>
|
||||||
<a href="https://slack.babeljs.io/"><img alt="Slack Status" src="https://slack.babeljs.io/badge.svg"></a>
|
<a href="https://slack.babeljs.io/"><img alt="Slack Status" src="https://slack.babeljs.io/badge.svg"></a>
|
||||||
<a href="https://www.npmjs.com/package/babel-core"><img alt="npm Downloads" src="https://img.shields.io/npm/dm/babel-core.svg?maxAge=43200"></a>
|
<a href="https://twitter.com/intent/follow?screen_name=babeljs"><img alt="Follow on Twitter" src="https://img.shields.io/twitter/follow/babeljs.svg?style=social&label=Follow"></a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h2 align="center">Supporting Babel</h2>
|
<h2 align="center">Supporting Babel</h2>
|
||||||
@@ -48,35 +52,15 @@ Become a sponsor and get your logo on our README on Github with a link to your s
|
|||||||
<a href="https://opencollective.com/babel/sponsor/12/website" target="_blank"><img src="https://opencollective.com/babel/sponsor/12/avatar.svg"></a>
|
<a href="https://opencollective.com/babel/sponsor/12/website" target="_blank"><img src="https://opencollective.com/babel/sponsor/12/avatar.svg"></a>
|
||||||
<a href="https://opencollective.com/babel/sponsor/13/website" target="_blank"><img src="https://opencollective.com/babel/sponsor/13/avatar.svg"></a>
|
<a href="https://opencollective.com/babel/sponsor/13/website" target="_blank"><img src="https://opencollective.com/babel/sponsor/13/avatar.svg"></a>
|
||||||
<a href="https://opencollective.com/babel/sponsor/14/website" target="_blank"><img src="https://opencollective.com/babel/sponsor/14/avatar.svg"></a>
|
<a href="https://opencollective.com/babel/sponsor/14/website" target="_blank"><img src="https://opencollective.com/babel/sponsor/14/avatar.svg"></a>
|
||||||
<a href="https://opencollective.com/babel/sponsor/15/website" target="_blank"><img src="https://opencollective.com/babel/sponsor/15/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/babel/sponsor/16/website" target="_blank"><img src="https://opencollective.com/babel/sponsor/16/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/babel/sponsor/17/website" target="_blank"><img src="https://opencollective.com/babel/sponsor/17/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/babel/sponsor/18/website" target="_blank"><img src="https://opencollective.com/babel/sponsor/18/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/babel/sponsor/19/website" target="_blank"><img src="https://opencollective.com/babel/sponsor/19/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/babel/sponsor/20/website" target="_blank"><img src="https://opencollective.com/babel/sponsor/20/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/babel/sponsor/21/website" target="_blank"><img src="https://opencollective.com/babel/sponsor/21/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/babel/sponsor/22/website" target="_blank"><img src="https://opencollective.com/babel/sponsor/22/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/babel/sponsor/23/website" target="_blank"><img src="https://opencollective.com/babel/sponsor/23/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/babel/sponsor/24/website" target="_blank"><img src="https://opencollective.com/babel/sponsor/24/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/babel/sponsor/25/website" target="_blank"><img src="https://opencollective.com/babel/sponsor/25/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/babel/sponsor/26/website" target="_blank"><img src="https://opencollective.com/babel/sponsor/26/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/babel/sponsor/27/website" target="_blank"><img src="https://opencollective.com/babel/sponsor/27/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/babel/sponsor/28/website" target="_blank"><img src="https://opencollective.com/babel/sponsor/28/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/babel/sponsor/29/website" target="_blank"><img src="https://opencollective.com/babel/sponsor/29/avatar.svg"></a>
|
|
||||||
|
|
||||||
## Patreon Sponsors
|
## Patreon Sponsors
|
||||||
|
|
||||||
Become a sponsor and get your logo on our README on Github with a link to your site. [[Become a sponsor](https://www.patreon.com/henryzhu)]
|
Become a sponsor and get your logo on our README on Github with a link to your site. [[Become a sponsor](https://www.patreon.com/henryzhu)]
|
||||||
|
|
||||||
## Silver
|
|
||||||
|
|
||||||
<a href="https://issue.sh/?utm_medium=github&utm_campaign=babel" target="_blank"><img src="https://user-images.githubusercontent.com/5557143/43912065-c8cdff78-9c33-11e8-829a-0b4166ccc215.png"></a>
|
|
||||||
|
|
||||||
## Bronze
|
## Bronze
|
||||||
|
|
||||||
<a href="http://teamextension.io/" target="_blank"><img src="https://teamextension.io/dist/img/logo/te-logo-compact.png" height="64"></a>
|
<a href="https://webflow.com" target="_blank"><img src="https://opencollective.com/proxy/images/?src=https%3A%2F%2Fopencollective-production.s3-us-west-1.amazonaws.com%2F4a5024b0-8cf2-11e7-b1a2-b30b1de1463c.png&height=64"></a>
|
||||||
<a href="https://webflow.com/" target="_blank"><img src="https://opencollective.com/proxy/images/?src=https%3A%2F%2Fopencollective-production.s3-us-west-1.amazonaws.com%2F4a5024b0-8cf2-11e7-b1a2-b30b1de1463c.png&height=64"></a>
|
<a href="https://issuehunt.io" target="_blank"><img src="https://github.com/BoostIO/issuehunt-materials/blob/master/v1/issuehunt-logo-and-word-v1.png?raw=true" height="64"></a>
|
||||||
<p><a href="https://twitter.com/mikesherov">Mike Sherov</a></p>
|
|
||||||
|
|
||||||
## Intro
|
## Intro
|
||||||
|
|
||||||
@@ -103,11 +87,11 @@ Try it out at our [REPL](https://babeljs.io/repl/build/master#?code_lz=NoRgNATGD
|
|||||||
|
|
||||||
### Who maintains Babel?
|
### Who maintains Babel?
|
||||||
|
|
||||||
Mostly a handful of volunteers! Please check out our [team page](https://babeljs.io/team)!
|
Mostly a handful of volunteers, funded by you! Please check out our [team page](https://babeljs.io/team)!
|
||||||
|
|
||||||
### Looking for support?
|
### Looking for support?
|
||||||
|
|
||||||
For questions and support please visit join our [Slack Community](https://slack.babeljs.io/) (you can sign-up [here](https://slack.babeljs.io/) for an invite), ask a question on [Stack Overflow](https://stackoverflow.com/questions/tagged/babeljs), or ping us on [Twitter](https://twitter.com/babeljs).
|
For questions and support please join our [Slack Community](https://slack.babeljs.io/) (you can sign-up [here](https://slack.babeljs.io/) for an invite), ask a question on [Stack Overflow](https://stackoverflow.com/questions/tagged/babeljs), or ping us on [Twitter](https://twitter.com/babeljs).
|
||||||
|
|
||||||
### Is there a Babel song?
|
### Is there a Babel song?
|
||||||
|
|
||||||
|
|||||||
@@ -14,12 +14,16 @@ module.exports = function(api) {
|
|||||||
let convertESM = true;
|
let convertESM = true;
|
||||||
let ignoreLib = true;
|
let ignoreLib = true;
|
||||||
let includeRuntime = false;
|
let includeRuntime = false;
|
||||||
|
const nodeVersion = "6.9";
|
||||||
|
|
||||||
switch (env) {
|
switch (env) {
|
||||||
// Configs used during bundling builds.
|
// Configs used during bundling builds.
|
||||||
case "babel-parser":
|
case "babel-parser":
|
||||||
convertESM = false;
|
convertESM = false;
|
||||||
ignoreLib = false;
|
ignoreLib = false;
|
||||||
|
envOpts.targets = {
|
||||||
|
node: nodeVersion,
|
||||||
|
};
|
||||||
break;
|
break;
|
||||||
case "standalone":
|
case "standalone":
|
||||||
convertESM = false;
|
convertESM = false;
|
||||||
@@ -29,7 +33,7 @@ module.exports = function(api) {
|
|||||||
case "production":
|
case "production":
|
||||||
// Config during builds before publish.
|
// Config during builds before publish.
|
||||||
envOpts.targets = {
|
envOpts.targets = {
|
||||||
node: "6.9",
|
node: nodeVersion,
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
case "development":
|
case "development":
|
||||||
|
|||||||
@@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
const noDeprecatedClone = require("./scripts/eslint_rules/no-deprecated-clone");
|
const noDeprecatedClone = require("./scripts/eslint_rules/no-deprecated-clone");
|
||||||
const noUndefinedIdentifier = require("./scripts/eslint_rules/no-undefined-identifier");
|
const noUndefinedIdentifier = require("./scripts/eslint_rules/no-undefined-identifier");
|
||||||
|
const pluginName = require("./scripts/eslint_rules/plugin-name");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"no-deprecated-clone": noDeprecatedClone,
|
"no-deprecated-clone": noDeprecatedClone,
|
||||||
"no-undefined-identifier": noUndefinedIdentifier,
|
"no-undefined-identifier": noUndefinedIdentifier,
|
||||||
|
"plugin-name": pluginName,
|
||||||
};
|
};
|
||||||
|
|||||||
15
lerna.json
15
lerna.json
@@ -1,6 +1,5 @@
|
|||||||
{
|
{
|
||||||
"lerna": "2.11.0",
|
"version": "7.3.2",
|
||||||
"version": "7.1.4",
|
|
||||||
"changelog": {
|
"changelog": {
|
||||||
"repo": "babel/babel",
|
"repo": "babel/babel",
|
||||||
"cacheDir": ".changelog",
|
"cacheDir": ".changelog",
|
||||||
@@ -14,21 +13,21 @@
|
|||||||
"PR: Internal :house:": ":house: Internal"
|
"PR: Internal :house:": ":house: Internal"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"commands": {
|
"command": {
|
||||||
"publish": {
|
"publish": {
|
||||||
"ignore": [
|
"ignoreChanges": [
|
||||||
"*.md",
|
"*.md",
|
||||||
"*.json",
|
|
||||||
"*.txt",
|
"*.txt",
|
||||||
"test/**",
|
"test/**",
|
||||||
"codemods/**",
|
"codemods/**",
|
||||||
"package.json"
|
"# We ignore every JSON file, except for built-in-modules, built-ins and plugins defined in babel-preset-env/data.",
|
||||||
|
"@(!(built-in-modules|built-ins|plugins)).json"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"packages": [
|
"packages": [
|
||||||
"packages/*",
|
"codemods/*",
|
||||||
"codemods/*"
|
"packages/*"
|
||||||
],
|
],
|
||||||
"npmClient": "yarn",
|
"npmClient": "yarn",
|
||||||
"npmClientArgs": [
|
"npmClientArgs": [
|
||||||
|
|||||||
@@ -2,12 +2,6 @@
|
|||||||
* Basic declarations for the npm modules we use.
|
* Basic declarations for the npm modules we use.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare module "micromatch" {
|
|
||||||
declare module.exports: {
|
|
||||||
(Array<string>, Array<string>, ?{ nocase: boolean }): Array<string>,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module "resolve" {
|
declare module "resolve" {
|
||||||
declare export default {
|
declare export default {
|
||||||
sync: (string, {| basedir: string |}) => string;
|
sync: (string, {| basedir: string |}) => string;
|
||||||
|
|||||||
91
package.json
91
package.json
@@ -9,69 +9,70 @@
|
|||||||
"test": "make test"
|
"test": "make test"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/cli": "^7.1.2",
|
"@babel/cli": "^7.2.3",
|
||||||
"@babel/core": "^7.1.2",
|
"@babel/core": "^7.2.2",
|
||||||
"@babel/plugin-proposal-class-properties": "^7.1.0",
|
"@babel/eslint-plugin-development": "^1.0.1",
|
||||||
"@babel/plugin-proposal-export-namespace-from": "^7.0.0",
|
"@babel/plugin-proposal-class-properties": "^7.3.0",
|
||||||
"@babel/plugin-proposal-numeric-separator": "^7.0.0",
|
"@babel/plugin-proposal-export-namespace-from": "^7.2.0",
|
||||||
"@babel/plugin-transform-modules-commonjs": "^7.1.0",
|
"@babel/plugin-proposal-numeric-separator": "^7.2.0",
|
||||||
"@babel/plugin-transform-runtime": "^7.1.0",
|
"@babel/plugin-transform-modules-commonjs": "^7.2.0",
|
||||||
"@babel/preset-env": "^7.1.0",
|
"@babel/plugin-transform-runtime": "^7.2.0",
|
||||||
|
"@babel/preset-env": "^7.3.1",
|
||||||
"@babel/preset-flow": "^7.0.0",
|
"@babel/preset-flow": "^7.0.0",
|
||||||
"@babel/register": "^7.0.0",
|
"@babel/register": "^7.0.0",
|
||||||
"@babel/runtime": "^7.1.2",
|
"@babel/runtime": "^7.3.1",
|
||||||
"babel-core": "^7.0.0-0",
|
"babel-eslint": "^11.0.0-beta.0",
|
||||||
"babel-eslint": "^10.0.1",
|
"babel-jest": "^24.0.0",
|
||||||
"babel-jest": "^23.6.0",
|
"babel-loader": "^8.0.5",
|
||||||
"babel-loader": "^8.0.4",
|
"babel-plugin-transform-charcodes": "^0.2.0",
|
||||||
"babel-plugin-transform-charcodes": "^0.1.0",
|
"browserify": "^16.2.3",
|
||||||
"browserify": "^16.2.2",
|
|
||||||
"bundle-collapser": "^1.2.1",
|
"bundle-collapser": "^1.2.1",
|
||||||
"chalk": "^2.3.2",
|
"chalk": "^2.3.2",
|
||||||
"charcodes": "^0.1.0",
|
"charcodes": "^0.2.0",
|
||||||
"derequire": "^2.0.2",
|
"derequire": "^2.0.2",
|
||||||
"enhanced-resolve": "^3.0.0",
|
"enhanced-resolve": "^3.0.0",
|
||||||
"eslint": "^5.6.0",
|
"eslint": "^5.12.1",
|
||||||
"eslint-config-babel": "^8.0.1",
|
"eslint-config-babel": "^8.0.2",
|
||||||
"eslint-plugin-flowtype": "^2.50.1",
|
"eslint-plugin-flowtype": "^3.2.1",
|
||||||
"eslint-plugin-local-rules": "0.1.0",
|
"eslint-plugin-prettier": "^3.0.1",
|
||||||
"eslint-plugin-prettier": "^2.6.2",
|
"fancy-log": "^1.3.3",
|
||||||
"flow-bin": "^0.82.0",
|
"flow-bin": "^0.87.0",
|
||||||
"graceful-fs": "^4.1.11",
|
"graceful-fs": "^4.1.15",
|
||||||
"gulp": "^4.0.0",
|
"gulp": "^4.0.0",
|
||||||
"gulp-babel": "^8.0.0-beta.2",
|
"gulp-babel": "^8.0.0",
|
||||||
"gulp-filter": "^5.1.0",
|
"gulp-filter": "^5.1.0",
|
||||||
"gulp-newer": "^1.0.0",
|
"gulp-newer": "^1.0.0",
|
||||||
"gulp-plumber": "^1.0.1",
|
"gulp-plumber": "^1.2.1",
|
||||||
"gulp-rename": "^1.2.2",
|
"gulp-rename": "^1.4.0",
|
||||||
"gulp-uglify": "^3.0.0",
|
"gulp-uglify": "^3.0.1",
|
||||||
"gulp-util": "^3.0.7",
|
"gulp-watch": "^5.0.1",
|
||||||
"gulp-watch": "^5.0.0",
|
"husky": "^1.3.1",
|
||||||
"husky": "^1.0.0-rc.15",
|
"jest": "^24.0.0",
|
||||||
"jest": "^23.6.0",
|
"lerna": "^3.6.0",
|
||||||
"lerna": "^2.11.0",
|
|
||||||
"lerna-changelog": "^0.5.0",
|
"lerna-changelog": "^0.5.0",
|
||||||
"lint-staged": "^7.3.0",
|
"lint-staged": "^8.1.0",
|
||||||
"lodash": "^4.17.10",
|
"lodash": "^4.17.11",
|
||||||
"merge-stream": "^1.0.1",
|
"merge-stream": "^1.0.1",
|
||||||
"output-file-sync": "^2.0.0",
|
"output-file-sync": "^2.0.0",
|
||||||
"prettier": "^1.14.3",
|
"prettier": "^1.16.1",
|
||||||
"pump": "^1.0.2",
|
"pump": "^3.0.0",
|
||||||
"rimraf": "^2.4.3",
|
"rimraf": "^2.6.3",
|
||||||
"rollup-plugin-babel": "^4.0.0-beta.0",
|
"rollup-plugin-babel": "^4.0.0-beta.0",
|
||||||
"rollup-plugin-node-resolve": "^3.0.2",
|
"rollup-plugin-node-resolve": "^3.0.2",
|
||||||
"rollup-stream": "^1.24.1",
|
"rollup-stream": "^1.24.1",
|
||||||
"test262-stream": "^1.2.0",
|
"test262-stream": "^1.2.0",
|
||||||
"through2": "^2.0.0",
|
"through2": "^2.0.0",
|
||||||
"uglify-js": "^2.4.16",
|
|
||||||
"vinyl-buffer": "^1.0.1",
|
"vinyl-buffer": "^1.0.1",
|
||||||
"vinyl-source-stream": "^2.0.0",
|
"vinyl-source-stream": "^2.0.0",
|
||||||
"webpack": "^3.4.1",
|
"webpack": "^3.4.1",
|
||||||
"webpack-dependency-suite": "^2.4.4",
|
"webpack-dependency-suite": "^2.4.4",
|
||||||
"webpack-stream": "^4.0.0"
|
"webpack-stream": "^4.0.0"
|
||||||
},
|
},
|
||||||
|
"resolutions": {
|
||||||
|
"@lerna/**/@lerna/collect-updates": "https://github.com/nicolo-ribaudo/lerna.git#babel-collect-updates"
|
||||||
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 6.9.0 <= 11.0.0-0",
|
"node": ">= 6.9.0 < 12.0.0",
|
||||||
"npm": ">= 3.x <= 6.x",
|
"npm": ">= 3.x <= 6.x",
|
||||||
"yarn": ">=0.27.5 || >=1.0.0-20170811"
|
"yarn": ">=0.27.5 || >=1.0.0-20170811"
|
||||||
},
|
},
|
||||||
@@ -106,7 +107,9 @@
|
|||||||
"_browser\\.js"
|
"_browser\\.js"
|
||||||
],
|
],
|
||||||
"testEnvironment": "node",
|
"testEnvironment": "node",
|
||||||
"setupTestFrameworkScriptFile": "<rootDir>/test/testSetupFile.js",
|
"setupFilesAfterEnv": [
|
||||||
|
"<rootDir>/test/testSetupFile.js"
|
||||||
|
],
|
||||||
"transformIgnorePatterns": [
|
"transformIgnorePatterns": [
|
||||||
"/node_modules/",
|
"/node_modules/",
|
||||||
"<rootDir>/packages/babel-standalone/babel(\\.min)?\\.js",
|
"<rootDir>/packages/babel-standalone/babel(\\.min)?\\.js",
|
||||||
@@ -125,6 +128,10 @@
|
|||||||
"/test/tmp/",
|
"/test/tmp/",
|
||||||
"/test/__data__/",
|
"/test/__data__/",
|
||||||
"<rootDir>/build/"
|
"<rootDir>/build/"
|
||||||
]
|
],
|
||||||
}
|
"moduleNameMapper": {
|
||||||
|
"^@babel/([a-zA-Z0-9_-]+)$": "<rootDir>/packages/babel-$1/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"dependencies": {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@babel/cli",
|
"name": "@babel/cli",
|
||||||
"version": "7.1.2",
|
"version": "7.2.3",
|
||||||
"description": "Babel command line.",
|
"description": "Babel command line.",
|
||||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||||
"homepage": "https://babeljs.io/",
|
"homepage": "https://babeljs.io/",
|
||||||
@@ -36,8 +36,8 @@
|
|||||||
"@babel/core": "^7.0.0-0"
|
"@babel/core": "^7.0.0-0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.0.0",
|
"@babel/core": "^7.2.0",
|
||||||
"@babel/helper-fixtures": "^7.0.0"
|
"@babel/helper-fixtures": "^7.2.0"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"babel": "./bin/babel.js",
|
"babel": "./bin/babel.js",
|
||||||
|
|||||||
@@ -137,7 +137,11 @@ export default async function({ cliOptions, babelOptions }) {
|
|||||||
const dirname = filename;
|
const dirname = filename;
|
||||||
|
|
||||||
util
|
util
|
||||||
.readdirForCompilable(filename, cliOptions.includeDotfiles)
|
.readdirForCompilable(
|
||||||
|
filename,
|
||||||
|
cliOptions.includeDotfiles,
|
||||||
|
cliOptions.extensions,
|
||||||
|
)
|
||||||
.forEach(function(filename) {
|
.forEach(function(filename) {
|
||||||
_filenames.push(path.join(dirname, filename));
|
_filenames.push(path.join(dirname, filename));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ commander.option(
|
|||||||
"comma-separated list of plugin names",
|
"comma-separated list of plugin names",
|
||||||
collect,
|
collect,
|
||||||
);
|
);
|
||||||
commander.option("--config-file [path]", "Path a to .babelrc file to use");
|
commander.option("--config-file [path]", "Path to a .babelrc file to use");
|
||||||
commander.option(
|
commander.option(
|
||||||
"--env-name [name]",
|
"--env-name [name]",
|
||||||
"The name of the 'env' to use when loading configs and plugins. " +
|
"The name of the 'env' to use when loading configs and plugins. " +
|
||||||
@@ -81,7 +81,7 @@ commander.option(
|
|||||||
"print a comment after any injected non-user code",
|
"print a comment after any injected non-user code",
|
||||||
);
|
);
|
||||||
|
|
||||||
// General soucemap formatting.
|
// General source map formatting.
|
||||||
commander.option("-s, --source-maps [true|false|inline|both]", "", booleanify);
|
commander.option("-s, --source-maps [true|false|inline|both]", "", booleanify);
|
||||||
commander.option(
|
commander.option(
|
||||||
"--source-map-target [string]",
|
"--source-map-target [string]",
|
||||||
|
|||||||
@@ -29,8 +29,11 @@ export function readdir(
|
|||||||
export function readdirForCompilable(
|
export function readdirForCompilable(
|
||||||
dirname: string,
|
dirname: string,
|
||||||
includeDotfiles: boolean,
|
includeDotfiles: boolean,
|
||||||
|
altExts?: Array<string>,
|
||||||
) {
|
) {
|
||||||
return readdir(dirname, includeDotfiles, isCompilableExtension);
|
return readdir(dirname, includeDotfiles, function(filename) {
|
||||||
|
return isCompilableExtension(filename, altExts);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
1
packages/babel-cli/test/fixtures/babel/dir --out-file --extensions/in-files/src/bar/bar.es
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/dir --out-file --extensions/in-files/src/bar/bar.es
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
(() => 42)
|
||||||
1
packages/babel-cli/test/fixtures/babel/dir --out-file --extensions/in-files/src/foo.es
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/dir --out-file --extensions/in-files/src/foo.es
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
arr.map(x => x * MULTIPLIER);
|
||||||
3
packages/babel-cli/test/fixtures/babel/dir --out-file --extensions/options.json
vendored
Normal file
3
packages/babel-cli/test/fixtures/babel/dir --out-file --extensions/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"args": ["src", "--out-file", "test.js", "--extensions", ".es"]
|
||||||
|
}
|
||||||
10
packages/babel-cli/test/fixtures/babel/dir --out-file --extensions/out-files/test.js
vendored
Normal file
10
packages/babel-cli/test/fixtures/babel/dir --out-file --extensions/out-files/test.js
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
(function () {
|
||||||
|
return 42;
|
||||||
|
});
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
arr.map(function (x) {
|
||||||
|
return x * MULTIPLIER;
|
||||||
|
});
|
||||||
0
packages/babel-cli/test/fixtures/babel/dir --out-file --extensions/stdout.txt
vendored
Normal file
0
packages/babel-cli/test/fixtures/babel/dir --out-file --extensions/stdout.txt
vendored
Normal file
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@babel/core",
|
"name": "@babel/core",
|
||||||
"version": "7.1.2",
|
"version": "7.2.2",
|
||||||
"description": "Babel compiler core.",
|
"description": "Babel compiler core.",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||||
@@ -34,15 +34,15 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/code-frame": "^7.0.0",
|
"@babel/code-frame": "^7.0.0",
|
||||||
"@babel/generator": "^7.1.2",
|
"@babel/generator": "^7.2.2",
|
||||||
"@babel/helpers": "^7.1.2",
|
"@babel/helpers": "^7.2.0",
|
||||||
"@babel/parser": "^7.1.2",
|
"@babel/parser": "^7.2.2",
|
||||||
"@babel/template": "^7.1.2",
|
"@babel/template": "^7.2.2",
|
||||||
"@babel/traverse": "^7.1.0",
|
"@babel/traverse": "^7.2.2",
|
||||||
"@babel/types": "^7.1.2",
|
"@babel/types": "^7.2.2",
|
||||||
"convert-source-map": "^1.1.0",
|
"convert-source-map": "^1.1.0",
|
||||||
"debug": "^3.1.0",
|
"debug": "^4.1.0",
|
||||||
"json5": "^0.5.0",
|
"json5": "^2.1.0",
|
||||||
"lodash": "^4.17.10",
|
"lodash": "^4.17.10",
|
||||||
"resolve": "^1.3.2",
|
"resolve": "^1.3.2",
|
||||||
"semver": "^5.4.1",
|
"semver": "^5.4.1",
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ export function makeWeakCache<
|
|||||||
>(
|
>(
|
||||||
handler: (ArgT, CacheConfigurator<SideChannel>) => ResultT,
|
handler: (ArgT, CacheConfigurator<SideChannel>) => ResultT,
|
||||||
): (ArgT, SideChannel) => ResultT {
|
): (ArgT, SideChannel) => ResultT {
|
||||||
|
// $FlowIssue https://github.com/facebook/flow/issues/4528
|
||||||
return makeCachedFunction(new WeakMap(), handler);
|
return makeCachedFunction(new WeakMap(), handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,6 +55,7 @@ function makeCachedFunction<
|
|||||||
ArgT,
|
ArgT,
|
||||||
ResultT,
|
ResultT,
|
||||||
SideChannel,
|
SideChannel,
|
||||||
|
// $FlowIssue https://github.com/facebook/flow/issues/4528
|
||||||
Cache: CacheMap<ArgT, ResultT, SideChannel>,
|
Cache: CacheMap<ArgT, ResultT, SideChannel>,
|
||||||
>(
|
>(
|
||||||
callCache: Cache,
|
callCache: Cache,
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ export function buildPresetChain(
|
|||||||
return {
|
return {
|
||||||
plugins: dedupDescriptors(chain.plugins),
|
plugins: dedupDescriptors(chain.plugins),
|
||||||
presets: dedupDescriptors(chain.presets),
|
presets: dedupDescriptors(chain.presets),
|
||||||
options: chain.options,
|
options: chain.options.map(o => normalizeOptions(o)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,6 +155,7 @@ export function buildRootChain(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let { babelrc, babelrcRoots } = opts;
|
let { babelrc, babelrcRoots } = opts;
|
||||||
|
let babelrcRootsDirectory = context.cwd;
|
||||||
|
|
||||||
const configFileChain = emptyChain();
|
const configFileChain = emptyChain();
|
||||||
if (configFile) {
|
if (configFile) {
|
||||||
@@ -168,6 +169,7 @@ export function buildRootChain(
|
|||||||
babelrc = validatedFile.options.babelrc;
|
babelrc = validatedFile.options.babelrc;
|
||||||
}
|
}
|
||||||
if (babelrcRoots === undefined) {
|
if (babelrcRoots === undefined) {
|
||||||
|
babelrcRootsDirectory = validatedFile.dirname;
|
||||||
babelrcRoots = validatedFile.options.babelrcRoots;
|
babelrcRoots = validatedFile.options.babelrcRoots;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,7 +187,7 @@ export function buildRootChain(
|
|||||||
if (
|
if (
|
||||||
(babelrc === true || babelrc === undefined) &&
|
(babelrc === true || babelrc === undefined) &&
|
||||||
pkgData &&
|
pkgData &&
|
||||||
babelrcLoadEnabled(context, pkgData, babelrcRoots)
|
babelrcLoadEnabled(context, pkgData, babelrcRoots, babelrcRootsDirectory)
|
||||||
) {
|
) {
|
||||||
({ ignore: ignoreFile, config: babelrcFile } = findRelativeConfig(
|
({ ignore: ignoreFile, config: babelrcFile } = findRelativeConfig(
|
||||||
pkgData,
|
pkgData,
|
||||||
@@ -229,6 +231,7 @@ function babelrcLoadEnabled(
|
|||||||
context: ConfigContext,
|
context: ConfigContext,
|
||||||
pkgData: FilePackageData,
|
pkgData: FilePackageData,
|
||||||
babelrcRoots: BabelrcSearch | void,
|
babelrcRoots: BabelrcSearch | void,
|
||||||
|
babelrcRootsDirectory: string,
|
||||||
): boolean {
|
): boolean {
|
||||||
if (typeof babelrcRoots === "boolean") return babelrcRoots;
|
if (typeof babelrcRoots === "boolean") return babelrcRoots;
|
||||||
|
|
||||||
@@ -243,7 +246,9 @@ function babelrcLoadEnabled(
|
|||||||
let babelrcPatterns = babelrcRoots;
|
let babelrcPatterns = babelrcRoots;
|
||||||
if (!Array.isArray(babelrcPatterns)) babelrcPatterns = [babelrcPatterns];
|
if (!Array.isArray(babelrcPatterns)) babelrcPatterns = [babelrcPatterns];
|
||||||
babelrcPatterns = babelrcPatterns.map(pat => {
|
babelrcPatterns = babelrcPatterns.map(pat => {
|
||||||
return typeof pat === "string" ? path.resolve(context.cwd, pat) : pat;
|
return typeof pat === "string"
|
||||||
|
? path.resolve(babelrcRootsDirectory, pat)
|
||||||
|
: pat;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Fast path to avoid having to match patterns if the babelrc is just
|
// Fast path to avoid having to match patterns if the babelrc is just
|
||||||
@@ -253,10 +258,12 @@ function babelrcLoadEnabled(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return babelrcPatterns.some(pat => {
|
return babelrcPatterns.some(pat => {
|
||||||
if (typeof pat === "string") pat = pathPatternToRegex(pat, context.cwd);
|
if (typeof pat === "string") {
|
||||||
|
pat = pathPatternToRegex(pat, babelrcRootsDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
return pkgData.directories.some(directory => {
|
return pkgData.directories.some(directory => {
|
||||||
return matchPattern(pat, context.cwd, directory, context);
|
return matchPattern(pat, babelrcRootsDirectory, directory, context);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ function resolveStandardizedName(
|
|||||||
} catch (e2) {}
|
} catch (e2) {}
|
||||||
|
|
||||||
if (resolvedOppositeType) {
|
if (resolvedOppositeType) {
|
||||||
e.message += `\n- Did you accidentally pass a ${type} as a ${oppositeType}?`;
|
e.message += `\n- Did you accidentally pass a ${oppositeType} as a ${type}?`;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw e;
|
throw e;
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ export default function makeAPI(
|
|||||||
async: () => false,
|
async: () => false,
|
||||||
caller,
|
caller,
|
||||||
assertVersion,
|
assertVersion,
|
||||||
|
tokTypes: undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -350,7 +350,7 @@ function validateNested(loc: NestingPath, opts: {}) {
|
|||||||
NONPRESET_VALIDATORS[key] ||
|
NONPRESET_VALIDATORS[key] ||
|
||||||
BABELRC_VALIDATORS[key] ||
|
BABELRC_VALIDATORS[key] ||
|
||||||
ROOT_VALIDATORS[key] ||
|
ROOT_VALIDATORS[key] ||
|
||||||
throwUnknownError;
|
(throwUnknownError: Validator<void>);
|
||||||
|
|
||||||
validator(optLoc, opts[key]);
|
validator(optLoc, opts[key]);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ export { version } from "../package.json";
|
|||||||
export { getEnv } from "./config/helpers/environment";
|
export { getEnv } from "./config/helpers/environment";
|
||||||
|
|
||||||
export * as types from "@babel/types";
|
export * as types from "@babel/types";
|
||||||
|
export { tokTypes } from "@babel/parser";
|
||||||
|
|
||||||
export { default as traverse } from "@babel/traverse";
|
export { default as traverse } from "@babel/traverse";
|
||||||
export { default as template } from "@babel/template";
|
export { default as template } from "@babel/template";
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,29 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import type { FileResult } from "./transformation";
|
|
||||||
|
|
||||||
export default function transformFile(
|
// duplicated from transform-file so we do not have to import anything here
|
||||||
filename: string,
|
type TransformFile = {
|
||||||
opts?: Object = {},
|
(filename: string, callback: Function): void,
|
||||||
callback: (?Error, FileResult | null) => void,
|
(filename: string, opts: ?Object, callback: Function): void,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const transformFile: TransformFile = (function transformFile(
|
||||||
|
filename,
|
||||||
|
opts,
|
||||||
|
callback,
|
||||||
) {
|
) {
|
||||||
if (typeof opts === "function") {
|
if (typeof opts === "function") {
|
||||||
callback = opts;
|
callback = opts;
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(new Error("Transforming files is not supported in browsers"), null);
|
callback(new Error("Transforming files is not supported in browsers"), null);
|
||||||
|
}: Function);
|
||||||
|
|
||||||
|
export function transformFileSync() {
|
||||||
|
throw new Error("Transforming files is not supported in browsers");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function transformFileAsync() {
|
||||||
|
return Promise.reject(
|
||||||
|
new Error("Transforming files is not supported in browsers"),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
// @flow
|
|
||||||
|
|
||||||
export default function transformFileSync() {
|
|
||||||
throw new Error("Transforming files is not supported in browsers");
|
|
||||||
}
|
|
||||||
@@ -9,6 +9,14 @@ import {
|
|||||||
type FileResultCallback,
|
type FileResultCallback,
|
||||||
} from "./transformation";
|
} from "./transformation";
|
||||||
|
|
||||||
|
import typeof * as transformFileBrowserType from "./transform-file-browser";
|
||||||
|
import typeof * as transformFileType from "./transform-file";
|
||||||
|
|
||||||
|
// Kind of gross, but essentially asserting that the exports of this module are the same as the
|
||||||
|
// exports of transform-file-browser, since this file may be replaced at bundle time with
|
||||||
|
// transform-file-browser.
|
||||||
|
((({}: any): $Exact<transformFileBrowserType>): $Exact<transformFileType>);
|
||||||
|
|
||||||
type TransformFile = {
|
type TransformFile = {
|
||||||
(filename: string, callback: FileResultCallback): void,
|
(filename: string, callback: FileResultCallback): void,
|
||||||
(filename: string, opts: ?InputOptions, callback: FileResultCallback): void,
|
(filename: string, opts: ?InputOptions, callback: FileResultCallback): void,
|
||||||
|
|||||||
@@ -1,16 +1,6 @@
|
|||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
const pluginNameMap = {
|
const pluginNameMap = {
|
||||||
asyncGenerators: {
|
|
||||||
syntax: {
|
|
||||||
name: "@babel/plugin-syntax-async-generators",
|
|
||||||
url: "https://git.io/vb4SY",
|
|
||||||
},
|
|
||||||
transform: {
|
|
||||||
name: "@babel/plugin-proposal-async-generator-functions",
|
|
||||||
url: "https://git.io/vb4yp",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
classProperties: {
|
classProperties: {
|
||||||
syntax: {
|
syntax: {
|
||||||
name: "@babel/plugin-syntax-class-properties",
|
name: "@babel/plugin-syntax-class-properties",
|
||||||
@@ -143,26 +133,6 @@ const pluginNameMap = {
|
|||||||
url: "https://git.io/vb4yS",
|
url: "https://git.io/vb4yS",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
objectRestSpread: {
|
|
||||||
syntax: {
|
|
||||||
name: "@babel/plugin-syntax-object-rest-spread",
|
|
||||||
url: "https://git.io/vb4y5",
|
|
||||||
},
|
|
||||||
transform: {
|
|
||||||
name: "@babel/plugin-proposal-object-rest-spread",
|
|
||||||
url: "https://git.io/vb4Ss",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
optionalCatchBinding: {
|
|
||||||
syntax: {
|
|
||||||
name: "@babel/plugin-syntax-optional-catch-binding",
|
|
||||||
url: "https://git.io/vb4Sn",
|
|
||||||
},
|
|
||||||
transform: {
|
|
||||||
name: "@babel/plugin-proposal-optional-catch-binding",
|
|
||||||
url: "https://git.io/vb4SI",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
optionalChaining: {
|
optionalChaining: {
|
||||||
syntax: {
|
syntax: {
|
||||||
name: "@babel/plugin-syntax-optional-chaining",
|
name: "@babel/plugin-syntax-optional-chaining",
|
||||||
@@ -203,6 +173,41 @@ const pluginNameMap = {
|
|||||||
url: "https://git.io/vb4Sm",
|
url: "https://git.io/vb4Sm",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// TODO: This plugins are now supported by default by @babel/parser: they can
|
||||||
|
// be removed from this list. Although removing them isn't a breaking change,
|
||||||
|
// it's better to keep a nice error message for users using older versions of
|
||||||
|
// the parser. They can be removed in Babel 8.
|
||||||
|
asyncGenerators: {
|
||||||
|
syntax: {
|
||||||
|
name: "@babel/plugin-syntax-async-generators",
|
||||||
|
url: "https://git.io/vb4SY",
|
||||||
|
},
|
||||||
|
transform: {
|
||||||
|
name: "@babel/plugin-proposal-async-generator-functions",
|
||||||
|
url: "https://git.io/vb4yp",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
objectRestSpread: {
|
||||||
|
syntax: {
|
||||||
|
name: "@babel/plugin-syntax-object-rest-spread",
|
||||||
|
url: "https://git.io/vb4y5",
|
||||||
|
},
|
||||||
|
transform: {
|
||||||
|
name: "@babel/plugin-proposal-object-rest-spread",
|
||||||
|
url: "https://git.io/vb4Ss",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
optionalCatchBinding: {
|
||||||
|
syntax: {
|
||||||
|
name: "@babel/plugin-syntax-optional-catch-binding",
|
||||||
|
url: "https://git.io/vb4Sn",
|
||||||
|
},
|
||||||
|
transform: {
|
||||||
|
name: "@babel/plugin-proposal-optional-catch-binding",
|
||||||
|
url: "https://git.io/vb4SI",
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const getNameURLCombination = ({ name, url }) => `${name} (${url})`;
|
const getNameURLCombination = ({ name, url }) => `${name} (${url})`;
|
||||||
|
|||||||
@@ -154,6 +154,14 @@ describe("api", function() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("exposes types", function() {
|
||||||
|
expect(babel.types).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("exposes the parser's token types", function() {
|
||||||
|
expect(babel.tokTypes).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
it("transformFile", function(done) {
|
it("transformFile", function(done) {
|
||||||
const options = {
|
const options = {
|
||||||
babelrc: false,
|
babelrc: false,
|
||||||
@@ -769,10 +777,10 @@ describe("api", function() {
|
|||||||
options,
|
options,
|
||||||
function(err) {
|
function(err) {
|
||||||
expect(err.message).toMatch(
|
expect(err.message).toMatch(
|
||||||
"Support for the experimental syntax 'asyncGenerators' isn't currently enabled (1:15):",
|
"Support for the experimental syntax 'logicalAssignment' isn't currently enabled (1:3):",
|
||||||
);
|
);
|
||||||
expect(err.message).toMatch(
|
expect(err.message).toMatch(
|
||||||
"Add @babel/plugin-proposal-async-generator-functions (https://git.io/vb4yp) to the " +
|
"Add @babel/plugin-proposal-logical-assignment-operators (https://git.io/vAlRe) to the " +
|
||||||
"'plugins' section of your Babel config to enable transformation.",
|
"'plugins' section of your Babel config to enable transformation.",
|
||||||
);
|
);
|
||||||
done();
|
done();
|
||||||
|
|||||||
@@ -1,4 +1 @@
|
|||||||
async function* agf() {
|
a ||= 2;
|
||||||
await 1;
|
|
||||||
yield 2;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -43,9 +43,11 @@ function () {
|
|||||||
}, _callee, this);
|
}, _callee, this);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return function bar() {
|
function bar() {
|
||||||
return _bar.apply(this, arguments);
|
return _bar.apply(this, arguments);
|
||||||
};
|
}
|
||||||
|
|
||||||
|
return bar;
|
||||||
}()
|
}()
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
{
|
{
|
||||||
"compact": false,
|
"compact": false,
|
||||||
"presets": ["env"],
|
"presets": ["env"],
|
||||||
"plugins": ["external-helpers", "proposal-object-rest-spread"]
|
"plugins": [
|
||||||
|
["external-helpers", { "helperVersion": "7.1.5" }],
|
||||||
|
"proposal-object-rest-spread"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -400,7 +400,7 @@ describe("addon resolution", function() {
|
|||||||
presets: ["testplugin"],
|
presets: ["testplugin"],
|
||||||
});
|
});
|
||||||
}).toThrow(
|
}).toThrow(
|
||||||
/Cannot find module 'babel-preset-testplugin'.*\n- Did you accidentally pass a preset as a plugin\?/,
|
/Cannot find module 'babel-preset-testplugin'.*\n- Did you accidentally pass a plugin as a preset\?/,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -414,7 +414,7 @@ describe("addon resolution", function() {
|
|||||||
plugins: ["testpreset"],
|
plugins: ["testpreset"],
|
||||||
});
|
});
|
||||||
}).toThrow(
|
}).toThrow(
|
||||||
/Cannot find module 'babel-plugin-testpreset'.*\n- Did you accidentally pass a plugin as a preset\?/,
|
/Cannot find module 'babel-plugin-testpreset'.*\n- Did you accidentally pass a preset as a plugin\?/,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@babel/generator",
|
"name": "@babel/generator",
|
||||||
"version": "7.1.3",
|
"version": "7.3.2",
|
||||||
"description": "Turns an AST into code.",
|
"description": "Turns an AST into code.",
|
||||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||||
"homepage": "https://babeljs.io/",
|
"homepage": "https://babeljs.io/",
|
||||||
@@ -14,14 +14,14 @@
|
|||||||
"lib"
|
"lib"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/types": "^7.1.3",
|
"@babel/types": "^7.3.2",
|
||||||
"jsesc": "^2.5.1",
|
"jsesc": "^2.5.1",
|
||||||
"lodash": "^4.17.10",
|
"lodash": "^4.17.10",
|
||||||
"source-map": "^0.5.0",
|
"source-map": "^0.5.0",
|
||||||
"trim-right": "^1.0.1"
|
"trim-right": "^1.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/helper-fixtures": "^7.0.0",
|
"@babel/helper-fixtures": "^7.2.0",
|
||||||
"@babel/parser": "^7.0.0"
|
"@babel/parser": "^7.3.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,6 +140,12 @@ export function ClassMethod(node: Object) {
|
|||||||
this.print(node.body, node);
|
this.print(node.body, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function ClassPrivateMethod(node: Object) {
|
||||||
|
this._classMethodHead(node);
|
||||||
|
this.space();
|
||||||
|
this.print(node.body, node);
|
||||||
|
}
|
||||||
|
|
||||||
export function _classMethodHead(node) {
|
export function _classMethodHead(node) {
|
||||||
this.printJoin(node.decorators, node);
|
this.printJoin(node.decorators, node);
|
||||||
|
|
||||||
|
|||||||
@@ -111,7 +111,25 @@ export function ArrowFunctionExpression(node: Object) {
|
|||||||
t.isIdentifier(firstParam) &&
|
t.isIdentifier(firstParam) &&
|
||||||
!hasTypes(node, firstParam)
|
!hasTypes(node, firstParam)
|
||||||
) {
|
) {
|
||||||
this.print(firstParam, node);
|
if (
|
||||||
|
this.format.retainLines &&
|
||||||
|
node.loc &&
|
||||||
|
node.body.loc &&
|
||||||
|
node.loc.start.line < node.body.loc.start.line
|
||||||
|
) {
|
||||||
|
this.token("(");
|
||||||
|
if (firstParam.loc && firstParam.loc.start.line > node.loc.start.line) {
|
||||||
|
this.indent();
|
||||||
|
this.print(firstParam, node);
|
||||||
|
this.dedent();
|
||||||
|
this._catchUp("start", node.body.loc);
|
||||||
|
} else {
|
||||||
|
this.print(firstParam, node);
|
||||||
|
}
|
||||||
|
this.token(")");
|
||||||
|
} else {
|
||||||
|
this.print(firstParam, node);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this._params(node);
|
this._params(node);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,3 +151,15 @@ export function BigIntLiteral(node: Object) {
|
|||||||
}
|
}
|
||||||
this.token(node.value);
|
this.token(node.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function PipelineTopicExpression(node: Object) {
|
||||||
|
this.print(node.expression, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PipelineBareFunction(node: Object) {
|
||||||
|
this.print(node.callee, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PipelinePrimaryTopicReference() {
|
||||||
|
this.token("#");
|
||||||
|
}
|
||||||
|
|||||||
@@ -476,6 +476,21 @@ export function TSModuleBlock(node) {
|
|||||||
this.tsPrintBraced(node.body, node);
|
this.tsPrintBraced(node.body, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function TSImportType(node) {
|
||||||
|
const { argument, qualifier, typeParameters } = node;
|
||||||
|
this.word("import");
|
||||||
|
this.token("(");
|
||||||
|
this.print(argument, node);
|
||||||
|
this.token(")");
|
||||||
|
if (qualifier) {
|
||||||
|
this.token(".");
|
||||||
|
this.print(qualifier, node);
|
||||||
|
}
|
||||||
|
if (typeParameters) {
|
||||||
|
this.print(typeParameters, node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function TSImportEqualsDeclaration(node) {
|
export function TSImportEqualsDeclaration(node) {
|
||||||
const { isExport, id, moduleReference } = node;
|
const { isExport, id, moduleReference } = node;
|
||||||
if (isExport) {
|
if (isExport) {
|
||||||
|
|||||||
@@ -166,6 +166,7 @@ export function YieldExpression(node: Object, parent: Object): boolean {
|
|||||||
t.isCallExpression(parent) ||
|
t.isCallExpression(parent) ||
|
||||||
t.isMemberExpression(parent) ||
|
t.isMemberExpression(parent) ||
|
||||||
t.isNewExpression(parent) ||
|
t.isNewExpression(parent) ||
|
||||||
|
(t.isAwaitExpression(parent) && t.isYieldExpression(node)) ||
|
||||||
(t.isConditionalExpression(parent) && node === parent.test) ||
|
(t.isConditionalExpression(parent) && node === parent.test) ||
|
||||||
isClassExtendsClause(node, parent)
|
isClassExtendsClause(node, parent)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -363,14 +363,14 @@ export default class Printer {
|
|||||||
}
|
}
|
||||||
if (needsParens) this.token("(");
|
if (needsParens) this.token("(");
|
||||||
|
|
||||||
this._printLeadingComments(node, parent);
|
this._printLeadingComments(node);
|
||||||
|
|
||||||
const loc = t.isProgram(node) || t.isFile(node) ? null : node.loc;
|
const loc = t.isProgram(node) || t.isFile(node) ? null : node.loc;
|
||||||
this.withSource("start", loc, () => {
|
this.withSource("start", loc, () => {
|
||||||
this[node.type](node, parent);
|
this[node.type](node, parent);
|
||||||
});
|
});
|
||||||
|
|
||||||
this._printTrailingComments(node, parent);
|
this._printTrailingComments(node);
|
||||||
|
|
||||||
if (needsParens) this.token(")");
|
if (needsParens) this.token(")");
|
||||||
|
|
||||||
@@ -472,12 +472,12 @@ export default class Printer {
|
|||||||
this.print(node, parent);
|
this.print(node, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
_printTrailingComments(node, parent) {
|
_printTrailingComments(node) {
|
||||||
this._printComments(this._getComments(false, node, parent));
|
this._printComments(this._getComments(false, node));
|
||||||
}
|
}
|
||||||
|
|
||||||
_printLeadingComments(node, parent) {
|
_printLeadingComments(node) {
|
||||||
this._printComments(this._getComments(true, node, parent));
|
this._printComments(this._getComments(true, node));
|
||||||
}
|
}
|
||||||
|
|
||||||
printInnerComments(node, indent = true) {
|
printInnerComments(node, indent = true) {
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
{ "plugins": ["objectRestSpread"] }
|
|
||||||
@@ -1 +1 @@
|
|||||||
{ "plugins": ["asyncGenerators", "classProperties"] }
|
{ "plugins": ["classProperties"] }
|
||||||
|
|||||||
11
packages/babel-generator/test/fixtures/edgecase/single-arg-async-arrow-with-retainlines/input.js
vendored
Normal file
11
packages/babel-generator/test/fixtures/edgecase/single-arg-async-arrow-with-retainlines/input.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
var fn = async (
|
||||||
|
arg
|
||||||
|
) => {}
|
||||||
|
|
||||||
|
async (x)
|
||||||
|
=> {}
|
||||||
|
|
||||||
|
async x => {}
|
||||||
|
|
||||||
|
async (x
|
||||||
|
) => {};
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"retainLines": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
var fn = async (
|
||||||
|
arg
|
||||||
|
) => {};
|
||||||
|
|
||||||
|
async (x) =>
|
||||||
|
{};
|
||||||
|
|
||||||
|
async x => {};
|
||||||
|
|
||||||
|
async (x) =>
|
||||||
|
{};
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
type A = interface { p: string };
|
type A = interface { p: string };
|
||||||
type B = interface extends X { p: string };
|
type B = interface extends X { p: string };
|
||||||
type C = interface extends X, Y { p: string };
|
type C = interface extends X, Y { p: string };
|
||||||
|
type D = interface extends X.Y<Z> { p: string };
|
||||||
|
|||||||
@@ -6,4 +6,7 @@ type B = interface extends X {
|
|||||||
};
|
};
|
||||||
type C = interface extends X, Y {
|
type C = interface extends X, Y {
|
||||||
p: string
|
p: string
|
||||||
};
|
};
|
||||||
|
type D = interface extends X.Y<Z> {
|
||||||
|
p: string
|
||||||
|
};
|
||||||
|
|||||||
@@ -14,3 +14,5 @@ type overloads =
|
|||||||
;
|
;
|
||||||
|
|
||||||
type func = string => string;
|
type func = string => string;
|
||||||
|
|
||||||
|
type D = X.Y<Z>;
|
||||||
|
|||||||
@@ -9,3 +9,4 @@ type union = {
|
|||||||
};
|
};
|
||||||
type overloads = (x: string) => number & (x: number) => string;
|
type overloads = (x: string) => number & (x: number) => string;
|
||||||
type func = (string) => string;
|
type func = (string) => string;
|
||||||
|
type D = X.Y<Z>;
|
||||||
|
|||||||
@@ -10,3 +10,7 @@ function* asdf() {
|
|||||||
function* a(b) {
|
function* a(b) {
|
||||||
(yield xhr({ url: "views/test.html" })).data;
|
(yield xhr({ url: "views/test.html" })).data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(async function* () {
|
||||||
|
await (yield 1);
|
||||||
|
});
|
||||||
|
|||||||
@@ -11,4 +11,8 @@ function* a(b) {
|
|||||||
(yield xhr({
|
(yield xhr({
|
||||||
url: "views/test.html"
|
url: "views/test.html"
|
||||||
})).data;
|
})).data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(async function* () {
|
||||||
|
await (yield 1);
|
||||||
|
});
|
||||||
|
|||||||
@@ -5,6 +5,15 @@ class Foo {
|
|||||||
get foo() {}
|
get foo() {}
|
||||||
set foo(bar) {}
|
set foo(bar) {}
|
||||||
|
|
||||||
|
async #foo() {}
|
||||||
|
#foo() {}
|
||||||
|
get #foo() {}
|
||||||
|
set #foo(bar) {}
|
||||||
|
* #foo() {}
|
||||||
|
async * #foo() {}
|
||||||
|
get #bar() {}
|
||||||
|
set #baz(taz) {}
|
||||||
|
|
||||||
static async foo() {}
|
static async foo() {}
|
||||||
static foo() {}
|
static foo() {}
|
||||||
static ["foo"]() {}
|
static ["foo"]() {}
|
||||||
@@ -52,4 +61,4 @@ class Foo {
|
|||||||
get
|
get
|
||||||
static
|
static
|
||||||
() {}
|
() {}
|
||||||
}
|
}
|
||||||
1
packages/babel-generator/test/fixtures/types/ClassBody-MethodDefinition/options.json
vendored
Normal file
1
packages/babel-generator/test/fixtures/types/ClassBody-MethodDefinition/options.json
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{ "plugins": ["classPrivateMethods", "asyncGenerators"] }
|
||||||
@@ -9,6 +9,22 @@ class Foo {
|
|||||||
|
|
||||||
set foo(bar) {}
|
set foo(bar) {}
|
||||||
|
|
||||||
|
async #foo() {}
|
||||||
|
|
||||||
|
#foo() {}
|
||||||
|
|
||||||
|
get #foo() {}
|
||||||
|
|
||||||
|
set #foo(bar) {}
|
||||||
|
|
||||||
|
*#foo() {}
|
||||||
|
|
||||||
|
async *#foo() {}
|
||||||
|
|
||||||
|
get #bar() {}
|
||||||
|
|
||||||
|
set #baz(taz) {}
|
||||||
|
|
||||||
static async foo() {}
|
static async foo() {}
|
||||||
|
|
||||||
static foo() {}
|
static foo() {}
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
{ "plugins": ["optionalCatchBinding"] }
|
|
||||||
1
packages/babel-generator/test/fixtures/types/PipelineBareFunction/input.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/types/PipelineBareFunction/input.js
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
let result = "hello" |> doubleSay |> text.capitalize |> a.b.exclaim;
|
||||||
3
packages/babel-generator/test/fixtures/types/PipelineBareFunction/options.json
vendored
Normal file
3
packages/babel-generator/test/fixtures/types/PipelineBareFunction/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"]
|
||||||
|
}
|
||||||
1
packages/babel-generator/test/fixtures/types/PipelineBareFunction/output.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/types/PipelineBareFunction/output.js
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
let result = "hello" |> doubleSay |> text.capitalize |> a.b.exclaim;
|
||||||
8
packages/babel-generator/test/fixtures/types/PipelineTopicExpression/input.js
vendored
Normal file
8
packages/babel-generator/test/fixtures/types/PipelineTopicExpression/input.js
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
value |> # + 1;
|
||||||
|
value |> 1 + #;
|
||||||
|
value |> do {
|
||||||
|
#;
|
||||||
|
};
|
||||||
|
value |> do {
|
||||||
|
if (yes) #;
|
||||||
|
};
|
||||||
3
packages/babel-generator/test/fixtures/types/PipelineTopicExpression/options.json
vendored
Normal file
3
packages/babel-generator/test/fixtures/types/PipelineTopicExpression/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"]
|
||||||
|
}
|
||||||
8
packages/babel-generator/test/fixtures/types/PipelineTopicExpression/output.js
vendored
Normal file
8
packages/babel-generator/test/fixtures/types/PipelineTopicExpression/output.js
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
value |> # + 1;
|
||||||
|
value |> 1 + #;
|
||||||
|
value |> do {
|
||||||
|
#;
|
||||||
|
};
|
||||||
|
value |> do {
|
||||||
|
if (yes) #;
|
||||||
|
};
|
||||||
@@ -1 +0,0 @@
|
|||||||
{ "plugins": ["objectRestSpread"] }
|
|
||||||
3
packages/babel-generator/test/fixtures/typescript/types-import-type/input.js
vendored
Normal file
3
packages/babel-generator/test/fixtures/typescript/types-import-type/input.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
let x: typeof import('./x');
|
||||||
|
let Y: import('./y').Y;
|
||||||
|
let z: import("/z").foo.bar<string>;
|
||||||
3
packages/babel-generator/test/fixtures/typescript/types-import-type/output.js
vendored
Normal file
3
packages/babel-generator/test/fixtures/typescript/types-import-type/output.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
let x: typeof import('./x');
|
||||||
|
let Y: import('./y').Y;
|
||||||
|
let z: import("/z").foo.bar<string>;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@babel/helper-builder-react-jsx",
|
"name": "@babel/helper-builder-react-jsx",
|
||||||
"version": "7.0.0",
|
"version": "7.3.0",
|
||||||
"description": "Helper function to build react jsx",
|
"description": "Helper function to build react jsx",
|
||||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-builder-react-jsx",
|
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-builder-react-jsx",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
},
|
},
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/types": "^7.0.0",
|
"@babel/types": "^7.3.0",
|
||||||
"esutils": "^2.0.0"
|
"esutils": "^2.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,13 @@ You can turn on the 'throwIfNamespace' flag to bypass this warning.`,
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
visitor.JSXSpreadChild = function(path) {
|
||||||
|
throw path.buildCodeFrameError(
|
||||||
|
"Spread children are not supported in React.",
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
visitor.JSXElement = {
|
visitor.JSXElement = {
|
||||||
exit(path, file) {
|
exit(path, file) {
|
||||||
const callExpr = buildElementCall(path, file);
|
const callExpr = buildElementCall(path, file);
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
src
|
||||||
|
test
|
||||||
|
*.log
|
||||||
19
packages/babel-helper-create-class-features-plugin/README.md
Normal file
19
packages/babel-helper-create-class-features-plugin/README.md
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# @babel/helper-create-class-features-plugin
|
||||||
|
|
||||||
|
> Compile class public and private fields, private methods and decorators to ES6
|
||||||
|
|
||||||
|
See our website [@babel/helper-create-class-features-plugin](https://babeljs.io/docs/en/next/babel-helper-create-class-features-plugin.html) for more information.
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
Using npm:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm install --save-dev @babel/helper-create-class-features-plugin
|
||||||
|
```
|
||||||
|
|
||||||
|
or using yarn:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
yarn add @babel/helper-create-class-features-plugin --dev
|
||||||
|
```
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"name": "@babel/helper-create-class-features-plugin",
|
||||||
|
"version": "7.3.2",
|
||||||
|
"author": "The Babel Team (https://babeljs.io/team)",
|
||||||
|
"license": "MIT",
|
||||||
|
"description": "Compile class public and private fields, private methods and decorators to ES6",
|
||||||
|
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-create-class-features-plugin",
|
||||||
|
"main": "lib/index.js",
|
||||||
|
"publishConfig": {
|
||||||
|
"access": "public"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"babel",
|
||||||
|
"babel-plugin"
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/helper-function-name": "^7.1.0",
|
||||||
|
"@babel/helper-member-expression-to-functions": "^7.0.0",
|
||||||
|
"@babel/helper-optimise-call-expression": "^7.0.0",
|
||||||
|
"@babel/helper-plugin-utils": "^7.0.0",
|
||||||
|
"@babel/helper-replace-supers": "^7.2.3"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@babel/core": "^7.0.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@babel/core": "^7.2.2",
|
||||||
|
"@babel/helper-plugin-test-runner": "^7.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,164 @@
|
|||||||
|
import { types as t, template } from "@babel/core";
|
||||||
|
import ReplaceSupers from "@babel/helper-replace-supers";
|
||||||
|
import nameFunction from "@babel/helper-function-name";
|
||||||
|
|
||||||
|
export function hasOwnDecorators(node) {
|
||||||
|
return !!(node.decorators && node.decorators.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hasDecorators(node) {
|
||||||
|
return hasOwnDecorators(node) || node.body.body.some(hasOwnDecorators);
|
||||||
|
}
|
||||||
|
|
||||||
|
function prop(key, value) {
|
||||||
|
if (!value) return null;
|
||||||
|
return t.objectProperty(t.identifier(key), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function method(key, body) {
|
||||||
|
return t.objectMethod(
|
||||||
|
"method",
|
||||||
|
t.identifier(key),
|
||||||
|
[],
|
||||||
|
t.blockStatement(body),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function takeDecorators(node) {
|
||||||
|
let result;
|
||||||
|
if (node.decorators && node.decorators.length > 0) {
|
||||||
|
result = t.arrayExpression(
|
||||||
|
node.decorators.map(decorator => decorator.expression),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
node.decorators = undefined;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getKey(node) {
|
||||||
|
if (node.computed) {
|
||||||
|
return node.key;
|
||||||
|
} else if (t.isIdentifier(node.key)) {
|
||||||
|
return t.stringLiteral(node.key.name);
|
||||||
|
} else {
|
||||||
|
return t.stringLiteral(String(node.key.value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: This function can be easily bound as .bind(file, classRef, superRef)
|
||||||
|
// to make it easier to use it in a loop.
|
||||||
|
function extractElementDescriptor(/* this: File, */ classRef, superRef, path) {
|
||||||
|
const { node, scope } = path;
|
||||||
|
const isMethod = path.isClassMethod();
|
||||||
|
|
||||||
|
if (path.isPrivate()) {
|
||||||
|
throw path.buildCodeFrameError(
|
||||||
|
`Private ${
|
||||||
|
isMethod ? "methods" : "fields"
|
||||||
|
} in decorated classes are not supported yet.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
new ReplaceSupers(
|
||||||
|
{
|
||||||
|
methodPath: path,
|
||||||
|
methodNode: node,
|
||||||
|
objectRef: classRef,
|
||||||
|
isStatic: node.static,
|
||||||
|
superRef,
|
||||||
|
scope,
|
||||||
|
file: this,
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
).replace();
|
||||||
|
|
||||||
|
const properties = [
|
||||||
|
prop("kind", t.stringLiteral(isMethod ? node.kind : "field")),
|
||||||
|
prop("decorators", takeDecorators(node)),
|
||||||
|
prop("static", node.static && t.booleanLiteral(true)),
|
||||||
|
prop("key", getKey(node)),
|
||||||
|
].filter(Boolean);
|
||||||
|
|
||||||
|
if (isMethod) {
|
||||||
|
const id = node.computed ? null : node.key;
|
||||||
|
t.toExpression(node);
|
||||||
|
properties.push(prop("value", nameFunction({ node, id, scope }) || node));
|
||||||
|
} else if (node.value) {
|
||||||
|
properties.push(
|
||||||
|
method("value", template.statements.ast`return ${node.value}`),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
properties.push(prop("value", scope.buildUndefinedNode()));
|
||||||
|
}
|
||||||
|
|
||||||
|
path.remove();
|
||||||
|
|
||||||
|
return t.objectExpression(properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
function addDecorateHelper(file) {
|
||||||
|
try {
|
||||||
|
return file.addHelper("decorate");
|
||||||
|
} catch (err) {
|
||||||
|
if (err.code === "BABEL_HELPER_UNKNOWN") {
|
||||||
|
err.message +=
|
||||||
|
"\n '@babel/plugin-transform-decorators' in non-legacy mode" +
|
||||||
|
" requires '@babel/core' version ^7.0.2 and you appear to be using" +
|
||||||
|
" an older version.";
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildDecoratedClass(ref, path, elements, file) {
|
||||||
|
const { node, scope } = path;
|
||||||
|
const initializeId = scope.generateUidIdentifier("initialize");
|
||||||
|
const isDeclaration = node.id && path.isDeclaration();
|
||||||
|
const isStrict = path.isInStrictMode();
|
||||||
|
const { superClass } = node;
|
||||||
|
|
||||||
|
node.type = "ClassDeclaration";
|
||||||
|
if (!node.id) node.id = t.cloneNode(ref);
|
||||||
|
|
||||||
|
let superId;
|
||||||
|
if (superClass) {
|
||||||
|
superId = scope.generateUidIdentifierBasedOnNode(node.superClass, "super");
|
||||||
|
node.superClass = superId;
|
||||||
|
}
|
||||||
|
|
||||||
|
const classDecorators = takeDecorators(node);
|
||||||
|
const definitions = t.arrayExpression(
|
||||||
|
elements.map(extractElementDescriptor.bind(file, node.id, superId)),
|
||||||
|
);
|
||||||
|
|
||||||
|
let replacement = template.expression.ast`
|
||||||
|
${addDecorateHelper(file)}(
|
||||||
|
${classDecorators || t.nullLiteral()},
|
||||||
|
function (${initializeId}, ${superClass ? superId : null}) {
|
||||||
|
${node}
|
||||||
|
return { F: ${t.cloneNode(node.id)}, d: ${definitions} };
|
||||||
|
},
|
||||||
|
${superClass}
|
||||||
|
)
|
||||||
|
`;
|
||||||
|
let classPathDesc = "arguments.1.body.body.0";
|
||||||
|
|
||||||
|
if (!isStrict) {
|
||||||
|
replacement.arguments[1].body.directives.push(
|
||||||
|
t.directive(t.directiveLiteral("use strict")),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isDeclaration) {
|
||||||
|
replacement = template.ast`let ${ref} = ${replacement}`;
|
||||||
|
classPathDesc = "declarations.0.init." + classPathDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
instanceNodes: [template.statement.ast`${initializeId}(this)`],
|
||||||
|
wrapClass(path) {
|
||||||
|
path.replaceWith(replacement);
|
||||||
|
return path.get(classPathDesc);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
import { hasOwnDecorators } from "./decorators";
|
||||||
|
|
||||||
|
export const FEATURES = Object.freeze({
|
||||||
|
//classes: 1 << 0,
|
||||||
|
fields: 1 << 1,
|
||||||
|
privateMethods: 1 << 2,
|
||||||
|
decorators: 1 << 3,
|
||||||
|
});
|
||||||
|
|
||||||
|
// We can't use a symbol because this needs to always be the same, even if
|
||||||
|
// this package isn't deduped by npm. e.g.
|
||||||
|
// - node_modules/
|
||||||
|
// - @babel/plugin-class-features
|
||||||
|
// - @babel/plugin-proposal-decorators
|
||||||
|
// - node_modules
|
||||||
|
// - @babel-plugin-class-features
|
||||||
|
const featuresKey = "@babel/plugin-class-features/featuresKey";
|
||||||
|
const looseKey = "@babel/plugin-class-features/looseKey";
|
||||||
|
|
||||||
|
export function enableFeature(file, feature, loose) {
|
||||||
|
// We can't blindly enable the feature because, if it was already set,
|
||||||
|
// "loose" can't be changed, so that
|
||||||
|
// @babel/plugin-class-properties { loose: true }
|
||||||
|
// @babel/plugin-class-properties { loose: false }
|
||||||
|
// is transformed in loose mode.
|
||||||
|
// We only enabled the feature if it was previously disabled.
|
||||||
|
if (!hasFeature(file, feature)) {
|
||||||
|
file.set(featuresKey, file.get(featuresKey) | feature);
|
||||||
|
if (loose) file.set(looseKey, file.get(looseKey) | feature);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasFeature(file, feature) {
|
||||||
|
return !!(file.get(featuresKey) & feature);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isLoose(file, feature) {
|
||||||
|
return !!(file.get(looseKey) & feature);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function verifyUsedFeatures(path, file) {
|
||||||
|
if (hasOwnDecorators(path.node)) {
|
||||||
|
if (!hasFeature(file, FEATURES.decorators)) {
|
||||||
|
throw path.buildCodeFrameError(
|
||||||
|
"Decorators are not enabled." +
|
||||||
|
"\nIf you are using " +
|
||||||
|
'["@babel/plugin-proposal-decorators", { "legacy": true }], ' +
|
||||||
|
'make sure it comes *before* "@babel/plugin-proposal-class-properties" ' +
|
||||||
|
"and enable loose mode, like so:\n" +
|
||||||
|
'\t["@babel/plugin-proposal-decorators", { "legacy": true }]\n' +
|
||||||
|
'\t["@babel/plugin-proposal-class-properties", { "loose": true }]',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path.isPrivate()) {
|
||||||
|
throw path.buildCodeFrameError(
|
||||||
|
`Private ${
|
||||||
|
path.isClassMethod() ? "methods" : "fields"
|
||||||
|
} in decorated classes are not supported yet.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: We can't use path.isPrivateMethod() because it isn't supported in <7.2.0
|
||||||
|
if (path.isPrivate() && path.isMethod()) {
|
||||||
|
if (!hasFeature(file, FEATURES.privateMethods)) {
|
||||||
|
throw path.buildCodeFrameError("Class private methods are not enabled.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path.node.static) {
|
||||||
|
throw path.buildCodeFrameError(
|
||||||
|
"@babel/plugin-class-features doesn't support class static private methods yet.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
hasFeature(file, FEATURES.privateMethods) &&
|
||||||
|
hasFeature(file, FEATURES.fields) &&
|
||||||
|
isLoose(file, FEATURES.privateMethods) !== isLoose(file, FEATURES.fields)
|
||||||
|
) {
|
||||||
|
throw path.buildCodeFrameError(
|
||||||
|
"'loose' mode configuration must be the same for both @babel/plugin-proposal-class-properties " +
|
||||||
|
"and @babel/plugin-proposal-private-methods",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path.isProperty()) {
|
||||||
|
if (!hasFeature(file, FEATURES.fields)) {
|
||||||
|
throw path.buildCodeFrameError("Class fields are not enabled.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
564
packages/babel-helper-create-class-features-plugin/src/fields.js
Normal file
564
packages/babel-helper-create-class-features-plugin/src/fields.js
Normal file
@@ -0,0 +1,564 @@
|
|||||||
|
import { template, traverse, types as t } from "@babel/core";
|
||||||
|
import { environmentVisitor } from "@babel/helper-replace-supers";
|
||||||
|
import memberExpressionToFunctions from "@babel/helper-member-expression-to-functions";
|
||||||
|
import optimiseCall from "@babel/helper-optimise-call-expression";
|
||||||
|
|
||||||
|
export function buildPrivateNamesMap(props) {
|
||||||
|
const privateNamesMap = new Map();
|
||||||
|
for (const prop of props) {
|
||||||
|
const isPrivate = prop.isPrivate();
|
||||||
|
const isMethod = !prop.isProperty();
|
||||||
|
const isInstance = !prop.node.static;
|
||||||
|
if (isPrivate) {
|
||||||
|
const { name } = prop.node.key.id;
|
||||||
|
const update = privateNamesMap.has(name)
|
||||||
|
? privateNamesMap.get(name)
|
||||||
|
: {
|
||||||
|
id: prop.scope.generateUidIdentifier(name),
|
||||||
|
static: !isInstance,
|
||||||
|
method: isMethod,
|
||||||
|
};
|
||||||
|
if (prop.node.kind === "get") {
|
||||||
|
update.getId = prop.scope.generateUidIdentifier(`get_${name}`);
|
||||||
|
} else if (prop.node.kind === "set") {
|
||||||
|
update.setId = prop.scope.generateUidIdentifier(`set_${name}`);
|
||||||
|
} else if (prop.node.kind === "method" && isMethod && isInstance) {
|
||||||
|
update.methodId = prop.scope.generateUidIdentifier(name);
|
||||||
|
}
|
||||||
|
privateNamesMap.set(name, update);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return privateNamesMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildPrivateNamesNodes(privateNamesMap, loose, state) {
|
||||||
|
const initNodes = [];
|
||||||
|
|
||||||
|
for (const [name, value] of privateNamesMap) {
|
||||||
|
// In loose mode, both static and instance fields are transpiled using a
|
||||||
|
// secret non-enumerable property. Hence, we also need to generate that
|
||||||
|
// key (using the classPrivateFieldLooseKey helper).
|
||||||
|
// In spec mode, only instance fields need a "private name" initializer
|
||||||
|
// because static fields are directly assigned to a variable in the
|
||||||
|
// buildPrivateStaticFieldInitSpec function.
|
||||||
|
const { id, static: isStatic, method: isMethod, getId, setId } = value;
|
||||||
|
if (loose) {
|
||||||
|
initNodes.push(
|
||||||
|
template.statement.ast`
|
||||||
|
var ${id} = ${state.addHelper("classPrivateFieldLooseKey")}("${name}")
|
||||||
|
`,
|
||||||
|
);
|
||||||
|
} else if (isMethod && !isStatic) {
|
||||||
|
if (getId || setId) {
|
||||||
|
initNodes.push(template.statement.ast`var ${id} = new WeakMap();`);
|
||||||
|
} else {
|
||||||
|
initNodes.push(template.statement.ast`var ${id} = new WeakSet();`);
|
||||||
|
}
|
||||||
|
} else if (!isStatic) {
|
||||||
|
initNodes.push(template.statement.ast`var ${id} = new WeakMap();`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return initNodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Traverses the class scope, handling private name references. If an inner
|
||||||
|
// class redeclares the same private name, it will hand off traversal to the
|
||||||
|
// restricted visitor (which doesn't traverse the inner class's inner scope).
|
||||||
|
const privateNameVisitor = {
|
||||||
|
PrivateName(path) {
|
||||||
|
const { privateNamesMap } = this;
|
||||||
|
const { node, parentPath } = path;
|
||||||
|
|
||||||
|
if (!parentPath.isMemberExpression({ property: node })) return;
|
||||||
|
if (!privateNamesMap.has(node.id.name)) return;
|
||||||
|
|
||||||
|
this.handle(parentPath);
|
||||||
|
},
|
||||||
|
|
||||||
|
Class(path) {
|
||||||
|
const { privateNamesMap } = this;
|
||||||
|
const body = path.get("body.body");
|
||||||
|
|
||||||
|
for (const prop of body) {
|
||||||
|
if (!prop.isPrivate()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!privateNamesMap.has(prop.node.key.id.name)) continue;
|
||||||
|
|
||||||
|
// This class redeclares the private name.
|
||||||
|
// So, we can only evaluate the things in the outer scope.
|
||||||
|
path.traverse(privateNameInnerVisitor, this);
|
||||||
|
path.skip();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Traverses the outer portion of a class, without touching the class's inner
|
||||||
|
// scope, for private names.
|
||||||
|
const privateNameInnerVisitor = traverse.visitors.merge([
|
||||||
|
{
|
||||||
|
PrivateName: privateNameVisitor.PrivateName,
|
||||||
|
},
|
||||||
|
environmentVisitor,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const privateNameHandlerSpec = {
|
||||||
|
memoise(member, count) {
|
||||||
|
const { scope } = member;
|
||||||
|
const { object } = member.node;
|
||||||
|
|
||||||
|
const memo = scope.maybeGenerateMemoised(object);
|
||||||
|
if (!memo) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.memoiser.set(object, memo, count);
|
||||||
|
},
|
||||||
|
|
||||||
|
receiver(member) {
|
||||||
|
const { object } = member.node;
|
||||||
|
|
||||||
|
if (this.memoiser.has(object)) {
|
||||||
|
return t.cloneNode(this.memoiser.get(object));
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.cloneNode(object);
|
||||||
|
},
|
||||||
|
|
||||||
|
get(member) {
|
||||||
|
const { classRef, privateNamesMap, file } = this;
|
||||||
|
const { name } = member.node.property.id;
|
||||||
|
const {
|
||||||
|
id,
|
||||||
|
static: isStatic,
|
||||||
|
method: isMethod,
|
||||||
|
methodId,
|
||||||
|
getId,
|
||||||
|
setId,
|
||||||
|
} = privateNamesMap.get(name);
|
||||||
|
|
||||||
|
if (isStatic && !isMethod) {
|
||||||
|
return t.callExpression(
|
||||||
|
file.addHelper("classStaticPrivateFieldSpecGet"),
|
||||||
|
[this.receiver(member), t.cloneNode(classRef), t.cloneNode(id)],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (isMethod) {
|
||||||
|
if (getId || setId) {
|
||||||
|
return t.callExpression(file.addHelper("classPrivateFieldGet"), [
|
||||||
|
this.receiver(member),
|
||||||
|
t.cloneNode(id),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
return t.callExpression(file.addHelper("classPrivateMethodGet"), [
|
||||||
|
this.receiver(member),
|
||||||
|
t.cloneNode(id),
|
||||||
|
t.cloneNode(methodId),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
return t.callExpression(file.addHelper("classPrivateFieldGet"), [
|
||||||
|
this.receiver(member),
|
||||||
|
t.cloneNode(id),
|
||||||
|
]);
|
||||||
|
},
|
||||||
|
|
||||||
|
set(member, value) {
|
||||||
|
const { classRef, privateNamesMap, file } = this;
|
||||||
|
const { name } = member.node.property.id;
|
||||||
|
const {
|
||||||
|
id,
|
||||||
|
static: isStatic,
|
||||||
|
method: isMethod,
|
||||||
|
setId,
|
||||||
|
} = privateNamesMap.get(name);
|
||||||
|
|
||||||
|
if (isStatic && !isMethod) {
|
||||||
|
return t.callExpression(
|
||||||
|
file.addHelper("classStaticPrivateFieldSpecSet"),
|
||||||
|
[this.receiver(member), t.cloneNode(classRef), t.cloneNode(id), value],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (isMethod) {
|
||||||
|
if (setId) {
|
||||||
|
return t.callExpression(file.addHelper("classPrivateFieldSet"), [
|
||||||
|
this.receiver(member),
|
||||||
|
t.cloneNode(id),
|
||||||
|
value,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
return t.callExpression(file.addHelper("classPrivateMethodSet"), []);
|
||||||
|
}
|
||||||
|
return t.callExpression(file.addHelper("classPrivateFieldSet"), [
|
||||||
|
this.receiver(member),
|
||||||
|
t.cloneNode(id),
|
||||||
|
value,
|
||||||
|
]);
|
||||||
|
},
|
||||||
|
|
||||||
|
call(member, args) {
|
||||||
|
// The first access (the get) should do the memo assignment.
|
||||||
|
this.memoise(member, 1);
|
||||||
|
|
||||||
|
return optimiseCall(this.get(member), this.receiver(member), args);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const privateNameHandlerLoose = {
|
||||||
|
handle(member) {
|
||||||
|
const { privateNamesMap, file } = this;
|
||||||
|
const { object } = member.node;
|
||||||
|
const { name } = member.node.property.id;
|
||||||
|
|
||||||
|
member.replaceWith(
|
||||||
|
template.expression`BASE(REF, PROP)[PROP]`({
|
||||||
|
BASE: file.addHelper("classPrivateFieldLooseBase"),
|
||||||
|
REF: object,
|
||||||
|
PROP: privateNamesMap.get(name).id,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export function transformPrivateNamesUsage(
|
||||||
|
ref,
|
||||||
|
path,
|
||||||
|
privateNamesMap,
|
||||||
|
loose,
|
||||||
|
state,
|
||||||
|
) {
|
||||||
|
const body = path.get("body");
|
||||||
|
|
||||||
|
if (loose) {
|
||||||
|
body.traverse(privateNameVisitor, {
|
||||||
|
privateNamesMap,
|
||||||
|
file: state,
|
||||||
|
...privateNameHandlerLoose,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
memberExpressionToFunctions(body, privateNameVisitor, {
|
||||||
|
privateNamesMap,
|
||||||
|
classRef: ref,
|
||||||
|
file: state,
|
||||||
|
...privateNameHandlerSpec,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildPrivateFieldInitLoose(ref, prop, privateNamesMap) {
|
||||||
|
const { id } = privateNamesMap.get(prop.node.key.id.name);
|
||||||
|
const value = prop.node.value || prop.scope.buildUndefinedNode();
|
||||||
|
|
||||||
|
return template.statement.ast`
|
||||||
|
Object.defineProperty(${ref}, ${id}, {
|
||||||
|
// configurable is false by default
|
||||||
|
// enumerable is false by default
|
||||||
|
writable: true,
|
||||||
|
value: ${value}
|
||||||
|
});
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildPrivateInstanceFieldInitSpec(ref, prop, privateNamesMap) {
|
||||||
|
const { id } = privateNamesMap.get(prop.node.key.id.name);
|
||||||
|
const value = prop.node.value || prop.scope.buildUndefinedNode();
|
||||||
|
|
||||||
|
return template.statement.ast`${id}.set(${ref}, {
|
||||||
|
// configurable is always false for private elements
|
||||||
|
// enumerable is always false for private elements
|
||||||
|
writable: true,
|
||||||
|
value: ${value},
|
||||||
|
})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildPrivateStaticFieldInitSpec(prop, privateNamesMap) {
|
||||||
|
const { id } = privateNamesMap.get(prop.node.key.id.name);
|
||||||
|
const value = prop.node.value || prop.scope.buildUndefinedNode();
|
||||||
|
|
||||||
|
return template.statement.ast`
|
||||||
|
var ${id} = {
|
||||||
|
// configurable is false by default
|
||||||
|
// enumerable is false by default
|
||||||
|
writable: true,
|
||||||
|
value: ${value}
|
||||||
|
};
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildPrivateMethodInitLoose(ref, prop, privateNamesMap) {
|
||||||
|
const privateName = privateNamesMap.get(prop.node.key.id.name);
|
||||||
|
const { methodId, id, getId, setId, initAdded } = privateName;
|
||||||
|
if (initAdded) return;
|
||||||
|
|
||||||
|
if (methodId) {
|
||||||
|
return template.statement.ast`
|
||||||
|
Object.defineProperty(${ref}, ${id}, {
|
||||||
|
// configurable is false by default
|
||||||
|
// enumerable is false by default
|
||||||
|
// writable is false by default
|
||||||
|
value: ${methodId.name}
|
||||||
|
});
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getId || setId) {
|
||||||
|
privateNamesMap.set(prop.node.key.id.name, {
|
||||||
|
...privateName,
|
||||||
|
initAdded: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (getId && setId) {
|
||||||
|
return template.statement.ast`
|
||||||
|
Object.defineProperty(${ref}, ${id}, {
|
||||||
|
// configurable is false by default
|
||||||
|
// enumerable is false by default
|
||||||
|
// writable is false by default
|
||||||
|
get: ${getId.name},
|
||||||
|
set: ${setId.name}
|
||||||
|
});
|
||||||
|
`;
|
||||||
|
} else if (getId && !setId) {
|
||||||
|
return template.statement.ast`
|
||||||
|
Object.defineProperty(${ref}, ${id}, {
|
||||||
|
// configurable is false by default
|
||||||
|
// enumerable is false by default
|
||||||
|
// writable is false by default
|
||||||
|
get: ${getId.name}
|
||||||
|
});
|
||||||
|
`;
|
||||||
|
} else if (!getId && setId) {
|
||||||
|
return template.statement.ast`
|
||||||
|
Object.defineProperty(${ref}, ${id}, {
|
||||||
|
// configurable is false by default
|
||||||
|
// enumerable is false by default
|
||||||
|
// writable is false by default
|
||||||
|
set: ${setId.name}
|
||||||
|
});
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildPrivateInstanceMethodInitSpec(ref, prop, privateNamesMap) {
|
||||||
|
const privateName = privateNamesMap.get(prop.node.key.id.name);
|
||||||
|
const { id, getId, setId, initAdded } = privateName;
|
||||||
|
if (initAdded) return;
|
||||||
|
|
||||||
|
if (getId || setId) {
|
||||||
|
privateNamesMap.set(prop.node.key.id.name, {
|
||||||
|
...privateName,
|
||||||
|
initAdded: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (getId && setId) {
|
||||||
|
return template.statement.ast`
|
||||||
|
${id}.set(${ref}, {
|
||||||
|
get: ${getId.name},
|
||||||
|
set: ${setId.name}
|
||||||
|
});
|
||||||
|
`;
|
||||||
|
} else if (getId && !setId) {
|
||||||
|
return template.statement.ast`
|
||||||
|
${id}.set(${ref}, {
|
||||||
|
get: ${getId.name}
|
||||||
|
});
|
||||||
|
`;
|
||||||
|
} else if (!getId && setId) {
|
||||||
|
return template.statement.ast`
|
||||||
|
${id}.set(${ref}, {
|
||||||
|
set: ${setId.name}
|
||||||
|
});
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return template.statement.ast`${id}.add(${ref})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildPublicFieldInitLoose(ref, prop) {
|
||||||
|
const { key, computed } = prop.node;
|
||||||
|
const value = prop.node.value || prop.scope.buildUndefinedNode();
|
||||||
|
|
||||||
|
return t.expressionStatement(
|
||||||
|
t.assignmentExpression(
|
||||||
|
"=",
|
||||||
|
t.memberExpression(ref, key, computed || t.isLiteral(key)),
|
||||||
|
value,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildPublicFieldInitSpec(ref, prop, state) {
|
||||||
|
const { key, computed } = prop.node;
|
||||||
|
const value = prop.node.value || prop.scope.buildUndefinedNode();
|
||||||
|
|
||||||
|
return t.expressionStatement(
|
||||||
|
t.callExpression(state.addHelper("defineProperty"), [
|
||||||
|
ref,
|
||||||
|
computed || t.isLiteral(key) ? key : t.stringLiteral(key.name),
|
||||||
|
value,
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildPrivateInstanceMethodDeclaration(prop, privateNamesMap) {
|
||||||
|
const privateName = privateNamesMap.get(prop.node.key.id.name);
|
||||||
|
const {
|
||||||
|
methodId,
|
||||||
|
getId,
|
||||||
|
setId,
|
||||||
|
getterDeclared,
|
||||||
|
setterDeclared,
|
||||||
|
} = privateName;
|
||||||
|
const { params, body, generator, async } = prop.node;
|
||||||
|
const methodValue = t.functionExpression(
|
||||||
|
methodId,
|
||||||
|
params,
|
||||||
|
body,
|
||||||
|
generator,
|
||||||
|
async,
|
||||||
|
);
|
||||||
|
const isGetter = getId && !getterDeclared && params.length === 0;
|
||||||
|
const isSetter = setId && !setterDeclared && params.length > 0;
|
||||||
|
|
||||||
|
if (isGetter) {
|
||||||
|
privateNamesMap.set(prop.node.key.id.name, {
|
||||||
|
...privateName,
|
||||||
|
getterDeclared: true,
|
||||||
|
});
|
||||||
|
return t.variableDeclaration("var", [
|
||||||
|
t.variableDeclarator(getId, methodValue),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
if (isSetter) {
|
||||||
|
privateNamesMap.set(prop.node.key.id.name, {
|
||||||
|
...privateName,
|
||||||
|
setterDeclared: true,
|
||||||
|
});
|
||||||
|
return t.variableDeclaration("var", [
|
||||||
|
t.variableDeclarator(setId, methodValue),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.variableDeclaration("var", [
|
||||||
|
t.variableDeclarator(methodId, methodValue),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildFieldsInitNodes(
|
||||||
|
ref,
|
||||||
|
props,
|
||||||
|
privateNamesMap,
|
||||||
|
state,
|
||||||
|
loose,
|
||||||
|
) {
|
||||||
|
const staticNodes = [];
|
||||||
|
const instanceNodes = [];
|
||||||
|
let needsClassRef = false;
|
||||||
|
|
||||||
|
for (const prop of props) {
|
||||||
|
const isStatic = prop.node.static;
|
||||||
|
const isInstance = !isStatic;
|
||||||
|
const isPrivate = prop.isPrivate();
|
||||||
|
const isPublic = !isPrivate;
|
||||||
|
const isField = prop.isProperty();
|
||||||
|
const isMethod = !isField;
|
||||||
|
|
||||||
|
switch (true) {
|
||||||
|
case isStatic && isPrivate && isField && loose:
|
||||||
|
needsClassRef = true;
|
||||||
|
staticNodes.push(
|
||||||
|
buildPrivateFieldInitLoose(t.cloneNode(ref), prop, privateNamesMap),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case isStatic && isPrivate && isField && !loose:
|
||||||
|
needsClassRef = true;
|
||||||
|
staticNodes.push(
|
||||||
|
buildPrivateStaticFieldInitSpec(prop, privateNamesMap),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case isStatic && isPublic && isField && loose:
|
||||||
|
needsClassRef = true;
|
||||||
|
staticNodes.push(buildPublicFieldInitLoose(t.cloneNode(ref), prop));
|
||||||
|
break;
|
||||||
|
case isStatic && isPublic && isField && !loose:
|
||||||
|
needsClassRef = true;
|
||||||
|
staticNodes.push(
|
||||||
|
buildPublicFieldInitSpec(t.cloneNode(ref), prop, state),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case isInstance && isPrivate && isField && loose:
|
||||||
|
instanceNodes.push(
|
||||||
|
buildPrivateFieldInitLoose(t.thisExpression(), prop, privateNamesMap),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case isInstance && isPrivate && isField && !loose:
|
||||||
|
instanceNodes.push(
|
||||||
|
buildPrivateInstanceFieldInitSpec(
|
||||||
|
t.thisExpression(),
|
||||||
|
prop,
|
||||||
|
privateNamesMap,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case isInstance && isPrivate && isMethod && loose:
|
||||||
|
instanceNodes.unshift(
|
||||||
|
buildPrivateMethodInitLoose(
|
||||||
|
t.thisExpression(),
|
||||||
|
prop,
|
||||||
|
privateNamesMap,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
staticNodes.push(
|
||||||
|
buildPrivateInstanceMethodDeclaration(prop, privateNamesMap),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case isInstance && isPrivate && isMethod && !loose:
|
||||||
|
instanceNodes.unshift(
|
||||||
|
buildPrivateInstanceMethodInitSpec(
|
||||||
|
t.thisExpression(),
|
||||||
|
prop,
|
||||||
|
privateNamesMap,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
staticNodes.push(
|
||||||
|
buildPrivateInstanceMethodDeclaration(prop, privateNamesMap),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case isInstance && isPublic && isField && loose:
|
||||||
|
instanceNodes.push(buildPublicFieldInitLoose(t.thisExpression(), prop));
|
||||||
|
break;
|
||||||
|
case isInstance && isPublic && isField && !loose:
|
||||||
|
instanceNodes.push(
|
||||||
|
buildPublicFieldInitSpec(t.thisExpression(), prop, state),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Error("Unreachable.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
staticNodes,
|
||||||
|
instanceNodes: instanceNodes.filter(Boolean),
|
||||||
|
wrapClass(path) {
|
||||||
|
for (const prop of props) {
|
||||||
|
prop.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!needsClassRef) return path;
|
||||||
|
|
||||||
|
if (path.isClassExpression()) {
|
||||||
|
path.scope.push({ id: ref });
|
||||||
|
path.replaceWith(
|
||||||
|
t.assignmentExpression("=", t.cloneNode(ref), path.node),
|
||||||
|
);
|
||||||
|
} else if (!path.node.id) {
|
||||||
|
// Anonymous class declaration
|
||||||
|
path.node.id = ref;
|
||||||
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
215
packages/babel-helper-create-class-features-plugin/src/index.js
Normal file
215
packages/babel-helper-create-class-features-plugin/src/index.js
Normal file
@@ -0,0 +1,215 @@
|
|||||||
|
import nameFunction from "@babel/helper-function-name";
|
||||||
|
import splitExportDeclaration from "@babel/helper-split-export-declaration";
|
||||||
|
import {
|
||||||
|
buildPrivateNamesNodes,
|
||||||
|
buildPrivateNamesMap,
|
||||||
|
transformPrivateNamesUsage,
|
||||||
|
buildFieldsInitNodes,
|
||||||
|
} from "./fields";
|
||||||
|
import {
|
||||||
|
hasOwnDecorators,
|
||||||
|
buildDecoratedClass,
|
||||||
|
hasDecorators,
|
||||||
|
} from "./decorators";
|
||||||
|
import { injectInitialization, extractComputedKeys } from "./misc";
|
||||||
|
import {
|
||||||
|
enableFeature,
|
||||||
|
verifyUsedFeatures,
|
||||||
|
FEATURES,
|
||||||
|
isLoose,
|
||||||
|
} from "./features";
|
||||||
|
|
||||||
|
import pkg from "../package.json";
|
||||||
|
|
||||||
|
export { FEATURES };
|
||||||
|
|
||||||
|
// Note: Versions are represented as an integer. e.g. 7.1.5 is represented
|
||||||
|
// as 70000100005. This method is easier than using a semver-parsing
|
||||||
|
// package, but it breaks if we relese x.y.z where x, y or z are
|
||||||
|
// greater than 99_999.
|
||||||
|
const version = pkg.version.split(".").reduce((v, x) => v * 1e5 + +x, 0);
|
||||||
|
const versionKey = "@babel/plugin-class-features/version";
|
||||||
|
|
||||||
|
export function createClassFeaturePlugin({
|
||||||
|
name,
|
||||||
|
feature,
|
||||||
|
loose,
|
||||||
|
manipulateOptions,
|
||||||
|
}) {
|
||||||
|
return {
|
||||||
|
name,
|
||||||
|
manipulateOptions,
|
||||||
|
|
||||||
|
pre() {
|
||||||
|
enableFeature(this.file, feature, loose);
|
||||||
|
|
||||||
|
if (!this.file.get(versionKey) || this.file.get(versionKey) < version) {
|
||||||
|
this.file.set(versionKey, version);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
visitor: {
|
||||||
|
Class(path, state) {
|
||||||
|
if (this.file.get(versionKey) !== version) return;
|
||||||
|
|
||||||
|
verifyUsedFeatures(path, this.file);
|
||||||
|
|
||||||
|
// Only fields are currently supported, this needs to be moved somewhere
|
||||||
|
// else when other features are added.
|
||||||
|
const loose = isLoose(this.file, FEATURES.fields);
|
||||||
|
|
||||||
|
let constructor;
|
||||||
|
let isDecorated = hasOwnDecorators(path.node);
|
||||||
|
const props = [];
|
||||||
|
const elements = [];
|
||||||
|
const computedPaths = [];
|
||||||
|
const privateNames = new Set();
|
||||||
|
const body = path.get("body");
|
||||||
|
|
||||||
|
for (const path of body.get("body")) {
|
||||||
|
verifyUsedFeatures(path, this.file);
|
||||||
|
|
||||||
|
if (path.node.computed) {
|
||||||
|
computedPaths.push(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path.isPrivate()) {
|
||||||
|
const { name } = path.node.key.id;
|
||||||
|
const getName = `get ${name}`;
|
||||||
|
const setName = `set ${name}`;
|
||||||
|
|
||||||
|
if (path.node.kind === "get") {
|
||||||
|
if (
|
||||||
|
privateNames.has(getName) ||
|
||||||
|
(privateNames.has(name) && !privateNames.has(setName))
|
||||||
|
) {
|
||||||
|
throw path.buildCodeFrameError("Duplicate private field");
|
||||||
|
}
|
||||||
|
|
||||||
|
privateNames.add(getName).add(name);
|
||||||
|
} else if (path.node.kind === "set") {
|
||||||
|
if (
|
||||||
|
privateNames.has(setName) ||
|
||||||
|
(privateNames.has(name) && !privateNames.has(getName))
|
||||||
|
) {
|
||||||
|
throw path.buildCodeFrameError("Duplicate private field");
|
||||||
|
}
|
||||||
|
|
||||||
|
privateNames.add(setName).add(name);
|
||||||
|
} else {
|
||||||
|
if (
|
||||||
|
(privateNames.has(name) &&
|
||||||
|
(!privateNames.has(getName) && !privateNames.has(setName))) ||
|
||||||
|
(privateNames.has(name) &&
|
||||||
|
(privateNames.has(getName) || privateNames.has(setName)))
|
||||||
|
) {
|
||||||
|
throw path.buildCodeFrameError("Duplicate private field");
|
||||||
|
}
|
||||||
|
|
||||||
|
privateNames.add(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path.isClassMethod({ kind: "constructor" })) {
|
||||||
|
constructor = path;
|
||||||
|
} else {
|
||||||
|
elements.push(path);
|
||||||
|
if (path.isProperty() || path.isPrivate()) {
|
||||||
|
props.push(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isDecorated) isDecorated = hasOwnDecorators(path.node);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!props.length && !isDecorated) return;
|
||||||
|
|
||||||
|
let ref;
|
||||||
|
|
||||||
|
if (path.isClassExpression() || !path.node.id) {
|
||||||
|
nameFunction(path);
|
||||||
|
ref = path.scope.generateUidIdentifier("class");
|
||||||
|
} else {
|
||||||
|
ref = path.node.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// NODE: These three functions don't support decorators yet,
|
||||||
|
// but verifyUsedFeatures throws if there are both
|
||||||
|
// decorators and private fields.
|
||||||
|
const privateNamesMap = buildPrivateNamesMap(props);
|
||||||
|
const privateNamesNodes = buildPrivateNamesNodes(
|
||||||
|
privateNamesMap,
|
||||||
|
loose,
|
||||||
|
state,
|
||||||
|
);
|
||||||
|
|
||||||
|
transformPrivateNamesUsage(ref, path, privateNamesMap, loose, state);
|
||||||
|
|
||||||
|
let keysNodes, staticNodes, instanceNodes, wrapClass;
|
||||||
|
|
||||||
|
if (isDecorated) {
|
||||||
|
staticNodes = keysNodes = [];
|
||||||
|
({ instanceNodes, wrapClass } = buildDecoratedClass(
|
||||||
|
ref,
|
||||||
|
path,
|
||||||
|
elements,
|
||||||
|
this.file,
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
keysNodes = extractComputedKeys(ref, path, computedPaths, this.file);
|
||||||
|
({ staticNodes, instanceNodes, wrapClass } = buildFieldsInitNodes(
|
||||||
|
ref,
|
||||||
|
props,
|
||||||
|
privateNamesMap,
|
||||||
|
state,
|
||||||
|
loose,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (instanceNodes.length > 0) {
|
||||||
|
injectInitialization(
|
||||||
|
path,
|
||||||
|
constructor,
|
||||||
|
instanceNodes,
|
||||||
|
(referenceVisitor, state) => {
|
||||||
|
if (isDecorated) return;
|
||||||
|
for (const prop of props) {
|
||||||
|
if (prop.node.static) continue;
|
||||||
|
prop.traverse(referenceVisitor, state);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
path = wrapClass(path);
|
||||||
|
path.insertBefore(keysNodes);
|
||||||
|
path.insertAfter([...privateNamesNodes, ...staticNodes]);
|
||||||
|
},
|
||||||
|
|
||||||
|
PrivateName(path) {
|
||||||
|
if (this.file.get(versionKey) !== version) return;
|
||||||
|
|
||||||
|
throw path.buildCodeFrameError(`Unknown PrivateName "${path}"`);
|
||||||
|
},
|
||||||
|
|
||||||
|
ExportDefaultDeclaration(path) {
|
||||||
|
if (this.file.get(versionKey) !== version) return;
|
||||||
|
|
||||||
|
const decl = path.get("declaration");
|
||||||
|
|
||||||
|
if (decl.isClassDeclaration() && hasDecorators(decl.node)) {
|
||||||
|
if (decl.node.id) {
|
||||||
|
// export default class Foo {}
|
||||||
|
// -->
|
||||||
|
// class Foo {} export { Foo as default }
|
||||||
|
splitExportDeclaration(path);
|
||||||
|
} else {
|
||||||
|
// Annyms class declarations can be
|
||||||
|
// transformed as if they were expressions
|
||||||
|
decl.node.type = "ClassExpression";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
111
packages/babel-helper-create-class-features-plugin/src/misc.js
Normal file
111
packages/babel-helper-create-class-features-plugin/src/misc.js
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
import { template, traverse, types as t } from "@babel/core";
|
||||||
|
import { environmentVisitor } from "@babel/helper-replace-supers";
|
||||||
|
|
||||||
|
const findBareSupers = traverse.visitors.merge([
|
||||||
|
{
|
||||||
|
Super(path) {
|
||||||
|
const { node, parentPath } = path;
|
||||||
|
if (parentPath.isCallExpression({ callee: node })) {
|
||||||
|
this.push(parentPath);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
environmentVisitor,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const referenceVisitor = {
|
||||||
|
"TSTypeAnnotation|TypeAnnotation"(path) {
|
||||||
|
path.skip();
|
||||||
|
},
|
||||||
|
|
||||||
|
ReferencedIdentifier(path) {
|
||||||
|
if (this.scope.hasOwnBinding(path.node.name)) {
|
||||||
|
this.scope.rename(path.node.name);
|
||||||
|
path.skip();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const classFieldDefinitionEvaluationTDZVisitor = traverse.visitors.merge([
|
||||||
|
{
|
||||||
|
ReferencedIdentifier(path) {
|
||||||
|
if (
|
||||||
|
this.classBinding &&
|
||||||
|
this.classBinding === path.scope.getBinding(path.node.name)
|
||||||
|
) {
|
||||||
|
const classNameTDZError = this.file.addHelper("classNameTDZError");
|
||||||
|
const throwNode = t.callExpression(classNameTDZError, [
|
||||||
|
t.stringLiteral(path.node.name),
|
||||||
|
]);
|
||||||
|
|
||||||
|
path.replaceWith(t.sequenceExpression([throwNode, path.node]));
|
||||||
|
path.skip();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
environmentVisitor,
|
||||||
|
]);
|
||||||
|
|
||||||
|
export function injectInitialization(path, constructor, nodes, renamer) {
|
||||||
|
if (!nodes.length) return;
|
||||||
|
|
||||||
|
const isDerived = !!path.node.superClass;
|
||||||
|
|
||||||
|
if (!constructor) {
|
||||||
|
const newConstructor = t.classMethod(
|
||||||
|
"constructor",
|
||||||
|
t.identifier("constructor"),
|
||||||
|
[],
|
||||||
|
t.blockStatement([]),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isDerived) {
|
||||||
|
newConstructor.params = [t.restElement(t.identifier("args"))];
|
||||||
|
newConstructor.body.body.push(template.statement.ast`super(...args)`);
|
||||||
|
}
|
||||||
|
|
||||||
|
[constructor] = path.get("body").unshiftContainer("body", newConstructor);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (renamer) {
|
||||||
|
renamer(referenceVisitor, { scope: constructor.scope });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isDerived) {
|
||||||
|
const bareSupers = [];
|
||||||
|
constructor.traverse(findBareSupers, bareSupers);
|
||||||
|
for (const bareSuper of bareSupers) {
|
||||||
|
bareSuper.insertAfter(nodes);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
constructor.get("body").unshiftContainer("body", nodes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function extractComputedKeys(ref, path, computedPaths, file) {
|
||||||
|
const declarations = [];
|
||||||
|
|
||||||
|
for (const computedPath of computedPaths) {
|
||||||
|
computedPath.traverse(classFieldDefinitionEvaluationTDZVisitor, {
|
||||||
|
classBinding: path.node.id && path.scope.getBinding(path.node.id.name),
|
||||||
|
file,
|
||||||
|
});
|
||||||
|
|
||||||
|
const computedNode = computedPath.node;
|
||||||
|
// Make sure computed property names are only evaluated once (upon class definition)
|
||||||
|
// and in the right order in combination with static properties
|
||||||
|
if (!computedPath.get("key").isConstantExpression()) {
|
||||||
|
const ident = path.scope.generateUidIdentifierBasedOnNode(
|
||||||
|
computedNode.key,
|
||||||
|
);
|
||||||
|
declarations.push(
|
||||||
|
t.variableDeclaration("var", [
|
||||||
|
t.variableDeclarator(ident, computedNode.key),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
computedNode.key = t.cloneNode(ident);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return declarations;
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
class A {
|
||||||
|
foo;
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
["proposal-class-properties", { "loose": true }, "name 1"],
|
||||||
|
["proposal-class-properties", { "loose": false }, "name 2"]
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
class A {
|
||||||
|
constructor() {
|
||||||
|
this.foo = void 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
const sym = Symbol();
|
||||||
|
const sym1 = Symbol();
|
||||||
|
|
||||||
|
class A {
|
||||||
|
[sym]: A.B;
|
||||||
|
[sym1]: Array<A>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"presets": ["flow"],
|
||||||
|
"plugins": ["proposal-class-properties"]
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||||
|
|
||||||
|
const sym = Symbol();
|
||||||
|
const sym1 = Symbol();
|
||||||
|
|
||||||
|
class A {
|
||||||
|
constructor() {
|
||||||
|
_defineProperty(this, sym, void 0);
|
||||||
|
|
||||||
|
_defineProperty(this, sym1, void 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user