-
Notifications
You must be signed in to change notification settings - Fork 139
/
babel.patch
234 lines (219 loc) · 10.8 KB
/
babel.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
diff --git a/Gulpfile.js b/Gulpfile.js
index c8a60079b..b49041ae6 100644
--- a/Gulpfile.js
+++ b/Gulpfile.js
@@ -4,7 +4,7 @@ const plumber = require("gulp-plumber");
const through = require("through2");
const chalk = require("chalk");
const newer = require("gulp-newer");
-const babel = require("gulp-babel");
+const sucrase = require("@sucrase/gulp-plugin");
const gulpWatch = require("gulp-watch");
const fancyLog = require("fancy-log");
const filter = require("gulp-filter");
@@ -66,7 +66,7 @@ function buildBabel(exclude, sourcesGlob = defaultSourcesGlob) {
.pipe(errorsLogger())
.pipe(newer({ dest: base, map: swapSrcWithLib }))
.pipe(compilationLogger())
- .pipe(babel())
+ .pipe(sucrase({transforms: ["flow", "imports"]}))
.pipe(
// Passing 'file.relative' because newer() above uses a relative
// path and this keeps it consistent.
@@ -105,7 +105,7 @@ function buildRollup(packages) {
);
}
-const bundles = ["packages/babel-parser"];
+const bundles = [];
gulp.task("build-rollup", () => buildRollup(bundles));
gulp.task("build-babel", () => buildBabel(/* exclude */ bundles));
diff --git a/Makefile b/Makefile
index 2c077a3fb..dfa6ff5e7 100644
--- a/Makefile
+++ b/Makefile
@@ -129,7 +129,9 @@ test-only:
BABEL_ENV=test ./scripts/test.sh
$(MAKE) test-clean
-test: lint test-only
+test:
+ make bootstrap
+ make test-only
test-ci: jest-ci
@@ -207,7 +209,14 @@ endif
rm -f .npmrc
$(MAKE) clean
-bootstrap-only: lerna-bootstrap
+bootstrap-only: clean-all
+ yarn --ignore-engines
+ yarn link sucrase
+ yarn link @sucrase/gulp-plugin
+ yarn link @sucrase/jest-plugin
+ yarn link @sucrase/webpack-loader
+ yarn link @sucrase/webpack-object-rest-spread-plugin
+ ./node_modules/.bin/lerna bootstrap
yarn-install: clean-all
yarn --ignore-engines
diff --git a/package.json b/package.json
index a420748f1..7678c4796 100644
--- a/package.json
+++ b/package.json
@@ -91,6 +91,9 @@
}
},
"jest": {
+ "transform": {
+ ".js": "@sucrase/jest-plugin"
+ },
"collectCoverageFrom": [
"packages/*/src/**/*.mjs",
"packages/*/src/**/*.js",
diff --git a/packages/babel-parser/src/util/scopeflags.js b/packages/babel-parser/src/util/scopeflags.js
index d92699883..2bdedecaa 100644
--- a/packages/babel-parser/src/util/scopeflags.js
+++ b/packages/babel-parser/src/util/scopeflags.js
@@ -2,18 +2,20 @@
// Each scope gets a bitset that may contain these flags
// prettier-ignore
-export const SCOPE_OTHER = 0b0000000000,
- SCOPE_PROGRAM = 0b0000000001,
- SCOPE_FUNCTION = 0b0000000010,
- SCOPE_ASYNC = 0b0000000100,
- SCOPE_GENERATOR = 0b0000001000,
- SCOPE_ARROW = 0b0000010000,
- SCOPE_SIMPLE_CATCH = 0b0000100000,
- SCOPE_SUPER = 0b0001000000,
- SCOPE_DIRECT_SUPER = 0b0010000000,
- SCOPE_CLASS = 0b0100000000,
- SCOPE_TS_MODULE = 0b1000000000,
- SCOPE_VAR = SCOPE_PROGRAM | SCOPE_FUNCTION | SCOPE_TS_MODULE;
+export const SCOPE_OTHER = 0b0000000000;
+// TODO(#455): This was changed to simpler code to work with Sucrase. Fix the
+// Sucrase bug to avoid this patch hunk.
+export const SCOPE_PROGRAM = 0b0000000001;
+export const SCOPE_FUNCTION = 0b0000000010;
+export const SCOPE_ASYNC = 0b0000000100;
+export const SCOPE_GENERATOR = 0b0000001000;
+export const SCOPE_ARROW = 0b0000010000;
+export const SCOPE_SIMPLE_CATCH = 0b0000100000;
+export const SCOPE_SUPER = 0b0001000000;
+export const SCOPE_DIRECT_SUPER = 0b0010000000;
+export const SCOPE_CLASS = 0b0100000000;
+export const SCOPE_TS_MODULE = 0b1000000000;
+export const SCOPE_VAR = SCOPE_PROGRAM | SCOPE_FUNCTION | SCOPE_TS_MODULE;
export type ScopeFlags =
| typeof SCOPE_OTHER
@@ -38,39 +40,39 @@ export function functionFlags(isAsync: boolean, isGenerator: boolean) {
// These flags are meant to be _only_ used inside the Scope class (or subclasses).
// prettier-ignore
-export const BIND_KIND_VALUE = 0b00000_0000_01,
- BIND_KIND_TYPE = 0b00000_0000_10,
+export const BIND_KIND_VALUE = 0b00000_0000_01;
+export const BIND_KIND_TYPE = 0b00000_0000_10;
// Used in checkLVal and declareName to determine the type of a binding
- BIND_SCOPE_VAR = 0b00000_0001_00, // Var-style binding
- BIND_SCOPE_LEXICAL = 0b00000_0010_00, // Let- or const-style binding
- BIND_SCOPE_FUNCTION = 0b00000_0100_00, // Function declaration
- BIND_SCOPE_OUTSIDE = 0b00000_1000_00, // Special case for function names as
+export const BIND_SCOPE_VAR = 0b00000_0001_00; // Var-style binding
+export const BIND_SCOPE_LEXICAL = 0b00000_0010_00; // Let- or const-style binding
+export const BIND_SCOPE_FUNCTION = 0b00000_0100_00; // Function declaration
+export const BIND_SCOPE_OUTSIDE = 0b00000_1000_00; // Special case for function names as
// bound inside the function
// Misc flags
- BIND_FLAGS_NONE = 0b00001_0000_00,
- BIND_FLAGS_CLASS = 0b00010_0000_00,
- BIND_FLAGS_TS_ENUM = 0b00100_0000_00,
- BIND_FLAGS_TS_CONST_ENUM = 0b01000_0000_00,
- BIND_FLAGS_TS_EXPORT_ONLY = 0b10000_0000_00;
+export const BIND_FLAGS_NONE = 0b00001_0000_00;
+export const BIND_FLAGS_CLASS = 0b00010_0000_00;
+export const BIND_FLAGS_TS_ENUM = 0b00100_0000_00;
+export const BIND_FLAGS_TS_CONST_ENUM = 0b01000_0000_00;
+export const BIND_FLAGS_TS_EXPORT_ONLY = 0b10000_0000_00;
// These flags are meant to be _only_ used by Scope consumers
// prettier-ignore
/* = is value? | is type? | scope | misc flags */
-export const BIND_CLASS = BIND_KIND_VALUE | BIND_KIND_TYPE | BIND_SCOPE_LEXICAL | BIND_FLAGS_CLASS ,
- BIND_LEXICAL = BIND_KIND_VALUE | 0 | BIND_SCOPE_LEXICAL | 0 ,
- BIND_VAR = BIND_KIND_VALUE | 0 | BIND_SCOPE_VAR | 0 ,
- BIND_FUNCTION = BIND_KIND_VALUE | 0 | BIND_SCOPE_FUNCTION | 0 ,
- BIND_TS_INTERFACE = 0 | BIND_KIND_TYPE | 0 | BIND_FLAGS_CLASS ,
- BIND_TS_TYPE = 0 | BIND_KIND_TYPE | 0 | 0 ,
- BIND_TS_ENUM = BIND_KIND_VALUE | BIND_KIND_TYPE | BIND_SCOPE_LEXICAL | BIND_FLAGS_TS_ENUM,
- BIND_TS_AMBIENT = 0 | 0 | 0 | BIND_FLAGS_TS_EXPORT_ONLY,
+export const BIND_CLASS = BIND_KIND_VALUE | BIND_KIND_TYPE | BIND_SCOPE_LEXICAL | BIND_FLAGS_CLASS ;
+export const BIND_LEXICAL = BIND_KIND_VALUE | 0 | BIND_SCOPE_LEXICAL | 0 ;
+export const BIND_VAR = BIND_KIND_VALUE | 0 | BIND_SCOPE_VAR | 0 ;
+export const BIND_FUNCTION = BIND_KIND_VALUE | 0 | BIND_SCOPE_FUNCTION | 0 ;
+export const BIND_TS_INTERFACE = 0 | BIND_KIND_TYPE | 0 | BIND_FLAGS_CLASS ;
+export const BIND_TS_TYPE = 0 | BIND_KIND_TYPE | 0 | 0 ;
+export const BIND_TS_ENUM = BIND_KIND_VALUE | BIND_KIND_TYPE | BIND_SCOPE_LEXICAL | BIND_FLAGS_TS_ENUM;
+export const BIND_TS_AMBIENT = 0 | 0 | 0 | BIND_FLAGS_TS_EXPORT_ONLY;
// These bindings don't introduce anything in the scope. They are used for assignments and
// function expressions IDs.
- BIND_NONE = 0 | 0 | 0 | BIND_FLAGS_NONE ,
- BIND_OUTSIDE = BIND_KIND_VALUE | 0 | 0 | BIND_FLAGS_NONE ,
+export const BIND_NONE = 0 | 0 | 0 | BIND_FLAGS_NONE ;
+export const BIND_OUTSIDE = BIND_KIND_VALUE | 0 | 0 | BIND_FLAGS_NONE ;
- BIND_TS_CONST_ENUM = BIND_TS_ENUM | BIND_FLAGS_TS_CONST_ENUM,
- BIND_TS_NAMESPACE = 0 | 0 | 0 | BIND_FLAGS_TS_EXPORT_ONLY;
+export const BIND_TS_CONST_ENUM = BIND_TS_ENUM | BIND_FLAGS_TS_CONST_ENUM;
+export const BIND_TS_NAMESPACE = 0 | 0 | 0 | BIND_FLAGS_TS_EXPORT_ONLY;
export type BindingTypes =
| typeof BIND_NONE
diff --git a/packages/babel-polyfill/src/index.js b/packages/babel-polyfill/src/index.js
index aa1b4639f..cca92db5a 100644
--- a/packages/babel-polyfill/src/index.js
+++ b/packages/babel-polyfill/src/index.js
@@ -7,7 +7,7 @@ if (global._babelPolyfill && typeof console !== "undefined" && console.warn) {
"@babel/polyfill is loaded more than once on this page. This is probably not desirable/intended " +
"and may have consequences if different versions of the polyfills are applied sequentially. " +
"If you do need to load the polyfill more than once, use @babel/polyfill/noConflict " +
- "instead to bypass the warning.",
+ "instead to bypass the warning."
);
}
diff --git a/packages/babel-preset-env/test/fixtures.js b/packages/babel-preset-env/test/fixtures.js
deleted file mode 100644
index 1b534b8fc..000000000
--- a/packages/babel-preset-env/test/fixtures.js
+++ /dev/null
@@ -1,3 +0,0 @@
-import runner from "@babel/helper-plugin-test-runner";
-
-runner(__dirname);
diff --git a/scripts/gulp-tasks.js b/scripts/gulp-tasks.js
index 73c1f7db2..59c35bfcf 100644
--- a/scripts/gulp-tasks.js
+++ b/scripts/gulp-tasks.js
@@ -23,6 +23,8 @@ const DuplicatePackageCheckerPlugin = require("duplicate-package-checker-webpack
const WarningsToErrorsPlugin = require("warnings-to-errors-webpack-plugin");
const webpackStream = require("webpack-stream");
const uglify = require("gulp-uglify");
+const ObjectRestSpreadPlugin = require("@sucrase/webpack-object-rest-spread-plugin");
+
function webpackBuild(opts) {
const plugins = opts.plugins || [];
@@ -41,12 +43,8 @@ function webpackBuild(opts) {
rules: [
{
test: /\.js$/,
- loader: "babel-loader",
- options: {
- // Use the bundled config so that module syntax is passed through
- // for Webpack.
- envName: "standalone",
- },
+ loader: "@sucrase/webpack-loader",
+ options: {transforms: ["imports", "flow"]},
},
],
},
@@ -63,6 +61,7 @@ function webpackBuild(opts) {
libraryTarget: "umd",
},
plugins: [
+ new ObjectRestSpreadPlugin(),
new WarningsToErrorsPlugin(),
new DuplicatePackageCheckerPlugin({
exclude(instance) {