Compare commits
42 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
d35563ee1a | ||
|
|
38397ce11f | ||
|
|
cd81b079ee | ||
|
|
e85faec47d | ||
|
|
0d9e77f559 | ||
|
|
c82750a48a | ||
|
|
de80aefece | ||
|
|
e4929e11f6 | ||
|
|
d942d47e10 | ||
|
|
84e7884d9c | ||
|
|
9d0dcedb2b | ||
|
|
b576bf4b41 | ||
|
|
e541d6031a | ||
|
|
5fa3628506 | ||
|
|
f71e4660d4 | ||
|
|
929567523c |
@@ -2542,7 +2542,7 @@ Also started Babel to compile itself with Babel 7! (We'll be working on making i
|
||||
|
||||
#### :nail_care: Polish
|
||||
* `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
|
||||
* `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.
|
||||
- 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)
|
||||
- [ ] 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)
|
||||
- [ ] Add failing/passing tests according to spec behavior
|
||||
- Start working about the Babel transform itself!
|
||||
|
||||
10
Makefile
10
Makefile
@@ -1,6 +1,6 @@
|
||||
MAKEFLAGS = -j1
|
||||
FLOW_COMMIT = bea8b83f50f597454941d2a7ecef6e93a881e576
|
||||
TEST262_COMMIT = 06c2f019019cf7850923de4d56828e6dfd9212b8
|
||||
FLOW_COMMIT = e192e1a4793dd8e43415fbfe8046d832cb513c8b
|
||||
TEST262_COMMIT = 69c1efd325deedf54db92a23008399e2b00fa51e
|
||||
|
||||
# Fix color output until TravisCI fixes https://github.com/travis-ci/travis-ci/issues/7967
|
||||
export FORCE_COLOR = true
|
||||
@@ -82,7 +82,7 @@ test-ci-coverage:
|
||||
bootstrap-flow:
|
||||
rm -rf ./build/flow
|
||||
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)
|
||||
|
||||
test-flow:
|
||||
@@ -96,7 +96,7 @@ test-flow-update-whitelist:
|
||||
bootstrap-test262:
|
||||
rm -rf ./build/test262
|
||||
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=2018-11-01 https://github.com/tc39/test262.git ./build/test262
|
||||
cd build/test262 && git checkout $(TEST262_COMMIT)
|
||||
|
||||
test-test262:
|
||||
@@ -125,7 +125,7 @@ prepublish:
|
||||
|
||||
publish: prepublish
|
||||
# --only-explicit-updates
|
||||
./node_modules/.bin/lerna publish
|
||||
./node_modules/.bin/lerna publish --force-publish="@babel/runtime,@babel/runtime-corejs2" --dangerously-only-publish-explicit-updates-this-is-a-custom-flag-for-babel-and-you-should-not-be-using-it-just-deal-with-more-packages-being-published-it-is-not-a-big-deal
|
||||
make clean
|
||||
|
||||
bootstrap: clean-all
|
||||
|
||||
@@ -107,7 +107,7 @@ Mostly a handful of volunteers! Please check out our [team page](https://babeljs
|
||||
|
||||
### 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?
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"lerna": "2.11.0",
|
||||
"version": "7.1.4",
|
||||
"version": "7.1.6",
|
||||
"changelog": {
|
||||
"repo": "babel/babel",
|
||||
"cacheDir": ".changelog",
|
||||
|
||||
@@ -2,12 +2,6 @@
|
||||
* 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 export default {
|
||||
sync: (string, {| basedir: string |}) => string;
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
"lodash": "^4.17.10",
|
||||
"merge-stream": "^1.0.1",
|
||||
"output-file-sync": "^2.0.0",
|
||||
"prettier": "^1.14.3",
|
||||
"prettier": "^1.15.1",
|
||||
"pump": "^1.0.2",
|
||||
"rimraf": "^2.4.3",
|
||||
"rollup-plugin-babel": "^4.0.0-beta.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/cli",
|
||||
"version": "7.1.2",
|
||||
"version": "7.1.5",
|
||||
"description": "Babel command line.",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
@@ -36,7 +36,7 @@
|
||||
"@babel/core": "^7.0.0-0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.0.0",
|
||||
"@babel/core": "^7.1.5",
|
||||
"@babel/helper-fixtures": "^7.0.0"
|
||||
},
|
||||
"bin": {
|
||||
|
||||
@@ -81,7 +81,7 @@ commander.option(
|
||||
"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(
|
||||
"--source-map-target [string]",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/core",
|
||||
"version": "7.1.2",
|
||||
"version": "7.1.6",
|
||||
"description": "Babel compiler core.",
|
||||
"main": "lib/index.js",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
@@ -34,15 +34,15 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/code-frame": "^7.0.0",
|
||||
"@babel/generator": "^7.1.2",
|
||||
"@babel/helpers": "^7.1.2",
|
||||
"@babel/parser": "^7.1.2",
|
||||
"@babel/generator": "^7.1.6",
|
||||
"@babel/helpers": "^7.1.5",
|
||||
"@babel/parser": "^7.1.6",
|
||||
"@babel/template": "^7.1.2",
|
||||
"@babel/traverse": "^7.1.0",
|
||||
"@babel/types": "^7.1.2",
|
||||
"@babel/traverse": "^7.1.6",
|
||||
"@babel/types": "^7.1.6",
|
||||
"convert-source-map": "^1.1.0",
|
||||
"debug": "^3.1.0",
|
||||
"json5": "^0.5.0",
|
||||
"debug": "^4.1.0",
|
||||
"json5": "^2.1.0",
|
||||
"lodash": "^4.17.10",
|
||||
"resolve": "^1.3.2",
|
||||
"semver": "^5.4.1",
|
||||
|
||||
@@ -155,6 +155,7 @@ export function buildRootChain(
|
||||
}
|
||||
|
||||
let { babelrc, babelrcRoots } = opts;
|
||||
let babelrcRootsDirectory = context.cwd;
|
||||
|
||||
const configFileChain = emptyChain();
|
||||
if (configFile) {
|
||||
@@ -168,6 +169,7 @@ export function buildRootChain(
|
||||
babelrc = validatedFile.options.babelrc;
|
||||
}
|
||||
if (babelrcRoots === undefined) {
|
||||
babelrcRootsDirectory = validatedFile.dirname;
|
||||
babelrcRoots = validatedFile.options.babelrcRoots;
|
||||
}
|
||||
|
||||
@@ -185,7 +187,7 @@ export function buildRootChain(
|
||||
if (
|
||||
(babelrc === true || babelrc === undefined) &&
|
||||
pkgData &&
|
||||
babelrcLoadEnabled(context, pkgData, babelrcRoots)
|
||||
babelrcLoadEnabled(context, pkgData, babelrcRoots, babelrcRootsDirectory)
|
||||
) {
|
||||
({ ignore: ignoreFile, config: babelrcFile } = findRelativeConfig(
|
||||
pkgData,
|
||||
@@ -229,6 +231,7 @@ function babelrcLoadEnabled(
|
||||
context: ConfigContext,
|
||||
pkgData: FilePackageData,
|
||||
babelrcRoots: BabelrcSearch | void,
|
||||
babelrcRootsDirectory: string,
|
||||
): boolean {
|
||||
if (typeof babelrcRoots === "boolean") return babelrcRoots;
|
||||
|
||||
@@ -243,7 +246,9 @@ function babelrcLoadEnabled(
|
||||
let babelrcPatterns = babelrcRoots;
|
||||
if (!Array.isArray(babelrcPatterns)) babelrcPatterns = [babelrcPatterns];
|
||||
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
|
||||
@@ -253,10 +258,12 @@ function babelrcLoadEnabled(
|
||||
}
|
||||
|
||||
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 matchPattern(pat, context.cwd, directory, context);
|
||||
return matchPattern(pat, babelrcRootsDirectory, directory, context);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ function resolveStandardizedName(
|
||||
} catch (e2) {}
|
||||
|
||||
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;
|
||||
|
||||
@@ -1,14 +1,29 @@
|
||||
// @flow
|
||||
import type { FileResult } from "./transformation";
|
||||
|
||||
export default function transformFile(
|
||||
filename: string,
|
||||
opts?: Object = {},
|
||||
callback: (?Error, FileResult | null) => void,
|
||||
// duplicated from transform-file so we do not have to import anything here
|
||||
type TransformFile = {
|
||||
(filename: string, callback: Function): void,
|
||||
(filename: string, opts: ?Object, callback: Function): void,
|
||||
};
|
||||
|
||||
export const transformFile: TransformFile = (function transformFile(
|
||||
filename,
|
||||
opts,
|
||||
callback,
|
||||
) {
|
||||
if (typeof opts === "function") {
|
||||
callback = opts;
|
||||
}
|
||||
|
||||
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,
|
||||
} 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 = {
|
||||
(filename: string, callback: FileResultCallback): void,
|
||||
(filename: string, opts: ?InputOptions, callback: FileResultCallback): void,
|
||||
|
||||
@@ -1,16 +1,6 @@
|
||||
// @flow
|
||||
|
||||
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: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-class-properties",
|
||||
@@ -143,26 +133,6 @@ const pluginNameMap = {
|
||||
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: {
|
||||
syntax: {
|
||||
name: "@babel/plugin-syntax-optional-chaining",
|
||||
@@ -203,6 +173,41 @@ const pluginNameMap = {
|
||||
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})`;
|
||||
|
||||
@@ -769,10 +769,10 @@ describe("api", function() {
|
||||
options,
|
||||
function(err) {
|
||||
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(
|
||||
"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.",
|
||||
);
|
||||
done();
|
||||
|
||||
@@ -1,4 +1 @@
|
||||
async function* agf() {
|
||||
await 1;
|
||||
yield 2;
|
||||
}
|
||||
a ||= 2;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
{
|
||||
"compact": false,
|
||||
"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"],
|
||||
});
|
||||
}).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"],
|
||||
});
|
||||
}).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",
|
||||
"version": "7.1.3",
|
||||
"version": "7.1.6",
|
||||
"description": "Turns an AST into code.",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
@@ -14,7 +14,7 @@
|
||||
"lib"
|
||||
],
|
||||
"dependencies": {
|
||||
"@babel/types": "^7.1.3",
|
||||
"@babel/types": "^7.1.6",
|
||||
"jsesc": "^2.5.1",
|
||||
"lodash": "^4.17.10",
|
||||
"source-map": "^0.5.0",
|
||||
@@ -22,6 +22,6 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/helper-fixtures": "^7.0.0",
|
||||
"@babel/parser": "^7.0.0"
|
||||
"@babel/parser": "^7.1.6"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +111,25 @@ export function ArrowFunctionExpression(node: Object) {
|
||||
t.isIdentifier(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 {
|
||||
this._params(node);
|
||||
}
|
||||
|
||||
@@ -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 +0,0 @@
|
||||
{ "plugins": ["optionalCatchBinding"] }
|
||||
@@ -1 +0,0 @@
|
||||
{ "plugins": ["objectRestSpread"] }
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/helpers",
|
||||
"version": "7.1.2",
|
||||
"version": "7.1.5",
|
||||
"description": "Collection of helper functions used by Babel transforms.",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
@@ -12,8 +12,8 @@
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/template": "^7.1.2",
|
||||
"@babel/traverse": "^7.1.0",
|
||||
"@babel/types": "^7.1.2"
|
||||
"@babel/traverse": "^7.1.5",
|
||||
"@babel/types": "^7.1.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/helper-plugin-test-runner": "^7.0.0"
|
||||
|
||||
@@ -935,13 +935,28 @@ helpers.skipFirstGeneratorNext = helper("7.0.0-beta.0")`
|
||||
}
|
||||
`;
|
||||
|
||||
helpers.toPropertyKey = helper("7.0.0-beta.0")`
|
||||
export default function _toPropertyKey(key) {
|
||||
if (typeof key === "symbol") {
|
||||
return key;
|
||||
} else {
|
||||
return String(key);
|
||||
helpers.toPrimitive = helper("7.1.5")`
|
||||
export default function _toPrimitive(
|
||||
input,
|
||||
hint /*: "default" | "string" | "number" | void */
|
||||
) {
|
||||
if (typeof input !== "object" || input === null) return input;
|
||||
var prim = input[Symbol.toPrimitive];
|
||||
if (prim !== undefined) {
|
||||
var res = prim.call(input, hint || "default");
|
||||
if (typeof res !== "object") return res;
|
||||
throw new TypeError("@@toPrimitive must return a primitive value.");
|
||||
}
|
||||
return (hint === "string" ? String : Number)(input);
|
||||
}
|
||||
`;
|
||||
|
||||
helpers.toPropertyKey = helper("7.1.5")`
|
||||
import toPrimitive from "toPrimitive";
|
||||
|
||||
export default function _toPropertyKey(arg) {
|
||||
var key = toPrimitive(arg, "string");
|
||||
return typeof key === "symbol" ? key : String(key);
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -1077,10 +1092,12 @@ helpers.classStaticPrivateFieldSpecSet = helper("7.0.2")`
|
||||
descriptor.value = value;
|
||||
return value;
|
||||
}
|
||||
|
||||
`;
|
||||
|
||||
helpers.decorate = helper("7.0.2")`
|
||||
helpers.decorate = helper("7.1.5")`
|
||||
import toArray from "toArray";
|
||||
import toPropertyKey from "toPropertyKey";
|
||||
|
||||
// These comments are stripped by @babel/template
|
||||
/*::
|
||||
@@ -1219,6 +1236,8 @@ helpers.decorate = helper("7.0.2")`
|
||||
function _createElementDescriptor(
|
||||
def /*: ElementDefinition */,
|
||||
) /*: ElementDescriptor */ {
|
||||
var key = toPropertyKey(def.key);
|
||||
|
||||
var descriptor /*: PropertyDescriptor */;
|
||||
if (def.kind === "method") {
|
||||
descriptor = {
|
||||
@@ -1227,6 +1246,10 @@ helpers.decorate = helper("7.0.2")`
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
};
|
||||
Object.defineProperty(def.value, "name", {
|
||||
value: typeof key === "symbol" ? "" : key,
|
||||
configurable: true,
|
||||
});
|
||||
} else if (def.kind === "get") {
|
||||
descriptor = { get: def.value, configurable: true, enumerable: false };
|
||||
} else if (def.kind === "set") {
|
||||
@@ -1237,7 +1260,7 @@ helpers.decorate = helper("7.0.2")`
|
||||
|
||||
var element /*: ElementDescriptor */ = {
|
||||
kind: def.kind === "field" ? "field" : "method",
|
||||
key: def.key,
|
||||
key: key,
|
||||
placement: def.static
|
||||
? "static"
|
||||
: def.kind === "field"
|
||||
@@ -1574,8 +1597,7 @@ helpers.decorate = helper("7.0.2")`
|
||||
);
|
||||
}
|
||||
|
||||
var key = elementObject.key;
|
||||
if (typeof key !== "string" && typeof key !== "symbol") key = String(key);
|
||||
var key = toPropertyKey(elementObject.key);
|
||||
|
||||
var placement = String(elementObject.placement);
|
||||
if (
|
||||
@@ -1716,4 +1738,4 @@ helpers.decorate = helper("7.0.2")`
|
||||
}
|
||||
return constructor;
|
||||
}
|
||||
`;
|
||||
`;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/parser",
|
||||
"version": "7.1.3",
|
||||
"version": "7.1.6",
|
||||
"description": "A JavaScript parser",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
|
||||
@@ -23,6 +23,7 @@ import * as N from "../types";
|
||||
import LValParser from "./lval";
|
||||
import { reservedWords } from "../util/identifier";
|
||||
import type { Pos, Position } from "../util/location";
|
||||
import * as charCodes from "charcodes";
|
||||
|
||||
export default class ExpressionParser extends LValParser {
|
||||
// Forward-declaration: defined in statement.js
|
||||
@@ -331,8 +332,8 @@ export default class ExpressionParser extends LValParser {
|
||||
this.finishNode(
|
||||
node,
|
||||
op === tt.logicalOR ||
|
||||
op === tt.logicalAND ||
|
||||
op === tt.nullishCoalescing
|
||||
op === tt.logicalAND ||
|
||||
op === tt.nullishCoalescing
|
||||
? "LogicalExpression"
|
||||
: "BinaryExpression",
|
||||
);
|
||||
@@ -522,10 +523,15 @@ export default class ExpressionParser extends LValParser {
|
||||
}
|
||||
return this.finishNode(node, "MemberExpression");
|
||||
} else if (!noCalls && this.match(tt.parenL)) {
|
||||
const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
|
||||
const oldYOAIPAP = this.state.yieldOrAwaitInPossibleArrowParameters;
|
||||
this.state.maybeInArrowParameters = true;
|
||||
this.state.yieldOrAwaitInPossibleArrowParameters = null;
|
||||
|
||||
const possibleAsync = this.atPossibleAsync(base);
|
||||
this.next();
|
||||
|
||||
const node = this.startNodeAt(startPos, startLoc);
|
||||
let node = this.startNodeAt(startPos, startLoc);
|
||||
node.callee = base;
|
||||
|
||||
// TODO: Clean up/merge this into `this.state` or a class like acorn's
|
||||
@@ -554,13 +560,22 @@ export default class ExpressionParser extends LValParser {
|
||||
);
|
||||
}
|
||||
|
||||
return this.parseAsyncArrowFromCallExpression(
|
||||
node = this.parseAsyncArrowFromCallExpression(
|
||||
this.startNodeAt(startPos, startLoc),
|
||||
node,
|
||||
);
|
||||
this.state.yieldOrAwaitInPossibleArrowParameters = oldYOAIPAP;
|
||||
} else {
|
||||
this.toReferencedList(node.arguments);
|
||||
|
||||
// We keep the old value if it isn't null, for cases like
|
||||
// (x = async(yield)) => {}
|
||||
this.state.yieldOrAwaitInPossibleArrowParameters =
|
||||
this.state.yieldOrAwaitInPossibleArrowParameters || oldYOAIPAP;
|
||||
}
|
||||
|
||||
this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
|
||||
|
||||
return node;
|
||||
} else if (this.match(tt.backQuote)) {
|
||||
return this.parseTaggedTemplateExpression(
|
||||
@@ -685,11 +700,8 @@ export default class ExpressionParser extends LValParser {
|
||||
node: N.ArrowFunctionExpression,
|
||||
call: N.CallExpression,
|
||||
): N.ArrowFunctionExpression {
|
||||
const oldYield = this.state.yieldInPossibleArrowParameters;
|
||||
this.state.yieldInPossibleArrowParameters = null;
|
||||
this.expect(tt.arrow);
|
||||
this.parseArrowExpression(node, call.arguments, true);
|
||||
this.state.yieldInPossibleArrowParameters = oldYield;
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -707,6 +719,10 @@ export default class ExpressionParser extends LValParser {
|
||||
// or `{}`.
|
||||
|
||||
parseExprAtom(refShorthandDefaultPos?: ?Pos): N.Expression {
|
||||
// If a division operator appears in an expression position, the
|
||||
// tokenizer got confused, and we force it to read a regexp instead.
|
||||
if (this.state.type === tt.slash) this.readRegexp();
|
||||
|
||||
const canBeArrow = this.state.potentialArrowAt === this.state.start;
|
||||
let node;
|
||||
|
||||
@@ -800,21 +816,24 @@ export default class ExpressionParser extends LValParser {
|
||||
id.name === "async" &&
|
||||
this.match(tt.name)
|
||||
) {
|
||||
const oldYield = this.state.yieldInPossibleArrowParameters;
|
||||
this.state.yieldInPossibleArrowParameters = null;
|
||||
const oldYOAIPAP = this.state.yieldOrAwaitInPossibleArrowParameters;
|
||||
const oldInAsync = this.state.inAsync;
|
||||
this.state.yieldOrAwaitInPossibleArrowParameters = null;
|
||||
this.state.inAsync = true;
|
||||
const params = [this.parseIdentifier()];
|
||||
this.expect(tt.arrow);
|
||||
// let foo = bar => {};
|
||||
// let foo = async bar => {};
|
||||
this.parseArrowExpression(node, params, true);
|
||||
this.state.yieldInPossibleArrowParameters = oldYield;
|
||||
this.state.yieldOrAwaitInPossibleArrowParameters = oldYOAIPAP;
|
||||
this.state.inAsync = oldInAsync;
|
||||
return node;
|
||||
}
|
||||
|
||||
if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) {
|
||||
const oldYield = this.state.yieldInPossibleArrowParameters;
|
||||
this.state.yieldInPossibleArrowParameters = null;
|
||||
const oldYOAIPAP = this.state.yieldOrAwaitInPossibleArrowParameters;
|
||||
this.state.yieldOrAwaitInPossibleArrowParameters = null;
|
||||
this.parseArrowExpression(node, [id]);
|
||||
this.state.yieldInPossibleArrowParameters = oldYield;
|
||||
this.state.yieldOrAwaitInPossibleArrowParameters = oldYOAIPAP;
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -950,7 +969,16 @@ export default class ExpressionParser extends LValParser {
|
||||
|
||||
parseFunctionExpression(): N.FunctionExpression | N.MetaProperty {
|
||||
const node = this.startNode();
|
||||
const meta = this.parseIdentifier(true);
|
||||
|
||||
// We do not do parseIdentifier here because when parseFunctionExpression
|
||||
// is called we already know that the current token is a "name" with the value "function"
|
||||
// This will improve perf a tiny little bit as we do not do validation but more importantly
|
||||
// here is that parseIdentifier will remove an item from the expression stack
|
||||
// if "function" or "class" is parsed as identifier (in objects e.g.), which should not happen here.
|
||||
let meta = this.startNode();
|
||||
this.next();
|
||||
meta = this.createIdentifier(meta, "function");
|
||||
|
||||
if (this.state.inGenerator && this.eat(tt.dot)) {
|
||||
return this.parseMetaProperty(node, meta, "sent");
|
||||
}
|
||||
@@ -1049,9 +1077,9 @@ export default class ExpressionParser extends LValParser {
|
||||
this.expect(tt.parenL);
|
||||
|
||||
const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
|
||||
const oldYield = this.state.yieldInPossibleArrowParameters;
|
||||
const oldYOAIPAP = this.state.yieldOrAwaitInPossibleArrowParameters;
|
||||
this.state.maybeInArrowParameters = true;
|
||||
this.state.yieldInPossibleArrowParameters = null;
|
||||
this.state.yieldOrAwaitInPossibleArrowParameters = null;
|
||||
|
||||
const innerStartPos = this.state.start;
|
||||
const innerStartLoc = this.state.startLoc;
|
||||
@@ -1124,11 +1152,14 @@ export default class ExpressionParser extends LValParser {
|
||||
}
|
||||
|
||||
this.parseArrowExpression(arrowNode, exprList);
|
||||
this.state.yieldInPossibleArrowParameters = oldYield;
|
||||
this.state.yieldOrAwaitInPossibleArrowParameters = oldYOAIPAP;
|
||||
return arrowNode;
|
||||
}
|
||||
|
||||
this.state.yieldInPossibleArrowParameters = oldYield;
|
||||
// We keep the old value if it isn't null, for cases like
|
||||
// (x = (yield)) => {}
|
||||
this.state.yieldOrAwaitInPossibleArrowParameters =
|
||||
this.state.yieldOrAwaitInPossibleArrowParameters || oldYOAIPAP;
|
||||
|
||||
if (!exprList.length) {
|
||||
this.unexpected(this.state.lastTokStart);
|
||||
@@ -1322,7 +1353,6 @@ export default class ExpressionParser extends LValParser {
|
||||
}
|
||||
|
||||
if (this.match(tt.ellipsis)) {
|
||||
this.expectPlugin("objectRestSpread");
|
||||
prop = this.parseSpread(isPattern ? { start: 0 } : undefined);
|
||||
if (isPattern) {
|
||||
this.toAssignable(prop, true, "object pattern");
|
||||
@@ -1382,11 +1412,7 @@ export default class ExpressionParser extends LValParser {
|
||||
prop.computed = false;
|
||||
} else {
|
||||
isAsync = true;
|
||||
if (this.match(tt.star)) {
|
||||
this.expectPlugin("asyncGenerators");
|
||||
this.next();
|
||||
isGenerator = true;
|
||||
}
|
||||
isGenerator = this.eat(tt.star);
|
||||
this.parsePropertyName(prop);
|
||||
}
|
||||
} else {
|
||||
@@ -1625,9 +1651,11 @@ export default class ExpressionParser extends LValParser {
|
||||
): T {
|
||||
const oldInFunc = this.state.inFunction;
|
||||
const oldInMethod = this.state.inMethod;
|
||||
const oldInAsync = this.state.inAsync;
|
||||
const oldInGenerator = this.state.inGenerator;
|
||||
this.state.inFunction = true;
|
||||
this.state.inMethod = node.kind || true;
|
||||
this.state.inAsync = isAsync;
|
||||
this.state.inGenerator = isGenerator;
|
||||
|
||||
this.initFunction(node, isAsync);
|
||||
@@ -1638,6 +1666,7 @@ export default class ExpressionParser extends LValParser {
|
||||
|
||||
this.state.inFunction = oldInFunc;
|
||||
this.state.inMethod = oldInMethod;
|
||||
this.state.inAsync = oldInAsync;
|
||||
this.state.inGenerator = oldInGenerator;
|
||||
|
||||
return node;
|
||||
@@ -1653,12 +1682,21 @@ export default class ExpressionParser extends LValParser {
|
||||
): N.ArrowFunctionExpression {
|
||||
// if we got there, it's no more "yield in possible arrow parameters";
|
||||
// it's just "yield in arrow parameters"
|
||||
if (this.state.yieldInPossibleArrowParameters) {
|
||||
this.raise(
|
||||
this.state.yieldInPossibleArrowParameters.start,
|
||||
"yield is not allowed in the parameters of an arrow function" +
|
||||
" inside a generator",
|
||||
);
|
||||
const yOAIPAP = this.state.yieldOrAwaitInPossibleArrowParameters;
|
||||
if (yOAIPAP) {
|
||||
if (yOAIPAP.type === "YieldExpression") {
|
||||
this.raise(
|
||||
yOAIPAP.start,
|
||||
"yield is not allowed in the parameters of an arrow function" +
|
||||
" inside a generator",
|
||||
);
|
||||
} else {
|
||||
this.raise(
|
||||
yOAIPAP.start,
|
||||
"await is not allowed in the parameters of an arrow function" +
|
||||
" inside an async function",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const oldInFunc = this.state.inFunction;
|
||||
@@ -1666,11 +1704,14 @@ export default class ExpressionParser extends LValParser {
|
||||
this.initFunction(node, isAsync);
|
||||
if (params) this.setArrowFunctionParameters(node, params);
|
||||
|
||||
const oldInAsync = this.state.inAsync;
|
||||
const oldInGenerator = this.state.inGenerator;
|
||||
const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
|
||||
this.state.inAsync = true;
|
||||
this.state.inGenerator = false;
|
||||
this.state.maybeInArrowParameters = false;
|
||||
this.parseFunctionBody(node, true);
|
||||
this.state.inAsync = oldInAsync;
|
||||
this.state.inGenerator = oldInGenerator;
|
||||
this.state.inFunction = oldInFunc;
|
||||
this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
|
||||
@@ -1718,9 +1759,7 @@ export default class ExpressionParser extends LValParser {
|
||||
const isExpression = allowExpression && !this.match(tt.braceL);
|
||||
|
||||
const oldInParameters = this.state.inParameters;
|
||||
const oldInAsync = this.state.inAsync;
|
||||
this.state.inParameters = false;
|
||||
this.state.inAsync = node.async;
|
||||
|
||||
if (isExpression) {
|
||||
node.body = this.parseMaybeAssign();
|
||||
@@ -1738,7 +1777,6 @@ export default class ExpressionParser extends LValParser {
|
||||
this.state.inGenerator = oldInGen;
|
||||
this.state.labels = oldLabels;
|
||||
}
|
||||
this.state.inAsync = oldInAsync;
|
||||
|
||||
this.checkFunctionNameAndParams(node, allowExpression);
|
||||
this.state.inParameters = oldInParameters;
|
||||
@@ -1839,8 +1877,14 @@ export default class ExpressionParser extends LValParser {
|
||||
parseIdentifier(liberal?: boolean): N.Identifier {
|
||||
const node = this.startNode();
|
||||
const name = this.parseIdentifierName(node.start, liberal);
|
||||
|
||||
return this.createIdentifier(node, name);
|
||||
}
|
||||
|
||||
createIdentifier(node: N.Identifier, name: string): N.Identifier {
|
||||
node.name = name;
|
||||
node.loc.identifierName = name;
|
||||
|
||||
return this.finishNode(node, "Identifier");
|
||||
}
|
||||
|
||||
@@ -1860,6 +1904,19 @@ export default class ExpressionParser extends LValParser {
|
||||
name = this.state.value;
|
||||
} else if (this.state.type.keyword) {
|
||||
name = this.state.type.keyword;
|
||||
|
||||
// `class` and `function` keywords push new context into this.context.
|
||||
// But there is no chance to pop the context if the keyword is consumed
|
||||
// as an identifier such as a property name.
|
||||
// If the previous token is a dot, this does not apply because the
|
||||
// context-managing code already ignored the keyword
|
||||
if (
|
||||
(name === "class" || name === "function") &&
|
||||
(this.state.lastTokEnd !== this.state.lastTokStart + 1 ||
|
||||
this.input.charCodeAt(this.state.lastTokStart) !== charCodes.dot)
|
||||
) {
|
||||
this.state.context.pop();
|
||||
}
|
||||
} else {
|
||||
throw this.unexpected();
|
||||
}
|
||||
@@ -1915,12 +1972,27 @@ export default class ExpressionParser extends LValParser {
|
||||
) {
|
||||
this.unexpected();
|
||||
}
|
||||
if (this.state.inParameters) {
|
||||
this.raise(
|
||||
node.start,
|
||||
"await is not allowed in async function parameters",
|
||||
);
|
||||
}
|
||||
if (this.match(tt.star)) {
|
||||
this.raise(
|
||||
node.start,
|
||||
"await* has been removed from the async functions proposal. Use Promise.all() instead.",
|
||||
);
|
||||
}
|
||||
if (
|
||||
this.state.maybeInArrowParameters &&
|
||||
// We only set yieldOrAwaitInPossibleArrowParameters if we haven't already
|
||||
// found a possible invalid AwaitExpression.
|
||||
!this.state.yieldOrAwaitInPossibleArrowParameters
|
||||
) {
|
||||
this.state.yieldOrAwaitInPossibleArrowParameters = node;
|
||||
}
|
||||
|
||||
node.argument = this.parseMaybeUnary();
|
||||
return this.finishNode(node, "AwaitExpression");
|
||||
}
|
||||
@@ -1935,11 +2007,11 @@ export default class ExpressionParser extends LValParser {
|
||||
}
|
||||
if (
|
||||
this.state.maybeInArrowParameters &&
|
||||
// We only set yieldInPossibleArrowParameters if we haven't already
|
||||
// We only set yieldOrAwaitInPossibleArrowParameters if we haven't already
|
||||
// found a possible invalid YieldExpression.
|
||||
!this.state.yieldInPossibleArrowParameters
|
||||
!this.state.yieldOrAwaitInPossibleArrowParameters
|
||||
) {
|
||||
this.state.yieldInPossibleArrowParameters = node;
|
||||
this.state.yieldOrAwaitInPossibleArrowParameters = node;
|
||||
}
|
||||
|
||||
this.next();
|
||||
|
||||
@@ -177,6 +177,7 @@ export default class LValParser extends NodeUtils {
|
||||
|
||||
toReferencedList(
|
||||
exprList: $ReadOnlyArray<?Expression>,
|
||||
isInParens?: boolean, // eslint-disable-line no-unused-vars
|
||||
): $ReadOnlyArray<?Expression> {
|
||||
return exprList;
|
||||
}
|
||||
|
||||
@@ -391,7 +391,6 @@ export default class StatementParser extends ExpressionParser {
|
||||
|
||||
let forAwait = false;
|
||||
if (this.state.inAsync && this.isContextual("await")) {
|
||||
this.expectPlugin("asyncGenerators");
|
||||
forAwait = true;
|
||||
this.next();
|
||||
}
|
||||
@@ -556,7 +555,6 @@ export default class StatementParser extends ExpressionParser {
|
||||
this.checkLVal(clause.param, true, clashes, "catch clause");
|
||||
this.expect(tt.parenR);
|
||||
} else {
|
||||
this.expectPlugin("optionalCatchBinding");
|
||||
clause.param = null;
|
||||
}
|
||||
clause.body = this.parseBlock();
|
||||
@@ -621,8 +619,8 @@ export default class StatementParser extends ExpressionParser {
|
||||
const kind = this.state.type.isLoop
|
||||
? "loop"
|
||||
: this.match(tt._switch)
|
||||
? "switch"
|
||||
: null;
|
||||
? "switch"
|
||||
: null;
|
||||
for (let i = this.state.labels.length - 1; i >= 0; i--) {
|
||||
const label = this.state.labels[i];
|
||||
if (label.statementStart === node.start) {
|
||||
@@ -844,6 +842,7 @@ export default class StatementParser extends ExpressionParser {
|
||||
): T {
|
||||
const oldInFunc = this.state.inFunction;
|
||||
const oldInMethod = this.state.inMethod;
|
||||
const oldInAsync = this.state.inAsync;
|
||||
const oldInGenerator = this.state.inGenerator;
|
||||
const oldInClassProperty = this.state.inClassProperty;
|
||||
this.state.inFunction = true;
|
||||
@@ -853,9 +852,6 @@ export default class StatementParser extends ExpressionParser {
|
||||
this.initFunction(node, isAsync);
|
||||
|
||||
if (this.match(tt.star)) {
|
||||
if (node.async) {
|
||||
this.expectPlugin("asyncGenerators");
|
||||
}
|
||||
node.generator = true;
|
||||
this.next();
|
||||
}
|
||||
@@ -877,11 +873,18 @@ export default class StatementParser extends ExpressionParser {
|
||||
// valid because yield is parsed as if it was outside the generator.
|
||||
// Therefore, this.state.inGenerator is set before or after parsing the
|
||||
// function id according to the "isStatement" parameter.
|
||||
if (!isStatement) this.state.inGenerator = node.generator;
|
||||
// The same applies to await & async functions.
|
||||
if (!isStatement) {
|
||||
this.state.inAsync = isAsync;
|
||||
this.state.inGenerator = node.generator;
|
||||
}
|
||||
if (this.match(tt.name) || this.match(tt._yield)) {
|
||||
node.id = this.parseBindingIdentifier();
|
||||
}
|
||||
if (isStatement) this.state.inGenerator = node.generator;
|
||||
if (isStatement) {
|
||||
this.state.inAsync = isAsync;
|
||||
this.state.inGenerator = node.generator;
|
||||
}
|
||||
|
||||
this.parseFunctionParams(node);
|
||||
this.parseFunctionBodyAndFinish(
|
||||
@@ -892,6 +895,7 @@ export default class StatementParser extends ExpressionParser {
|
||||
|
||||
this.state.inFunction = oldInFunc;
|
||||
this.state.inMethod = oldInMethod;
|
||||
this.state.inAsync = oldInAsync;
|
||||
this.state.inGenerator = oldInGenerator;
|
||||
this.state.inClassProperty = oldInClassProperty;
|
||||
|
||||
@@ -1153,11 +1157,7 @@ export default class StatementParser extends ExpressionParser {
|
||||
}
|
||||
} else if (isSimple && key.name === "async" && !this.isLineTerminator()) {
|
||||
// an async method
|
||||
const isGenerator = this.match(tt.star);
|
||||
if (isGenerator) {
|
||||
this.expectPlugin("asyncGenerators");
|
||||
this.next();
|
||||
}
|
||||
const isGenerator = this.eat(tt.star);
|
||||
|
||||
method.kind = "method";
|
||||
// The so-called parsed name would have been "async": get the real name.
|
||||
|
||||
@@ -6,10 +6,11 @@ import * as N from "../types";
|
||||
import type { Options } from "../options";
|
||||
import type { Pos, Position } from "../util/location";
|
||||
import type State from "../tokenizer/state";
|
||||
import { types as tc } from "../tokenizer/context";
|
||||
import * as charCodes from "charcodes";
|
||||
import { isIteratorStart } from "../util/identifier";
|
||||
|
||||
const primitiveTypes = [
|
||||
const reservedTypes = [
|
||||
"any",
|
||||
"bool",
|
||||
"boolean",
|
||||
@@ -23,6 +24,9 @@ const primitiveTypes = [
|
||||
"true",
|
||||
"typeof",
|
||||
"void",
|
||||
"interface",
|
||||
"extends",
|
||||
"_",
|
||||
];
|
||||
|
||||
function isEsModuleType(bodyElement: N.Node): boolean {
|
||||
@@ -463,7 +467,13 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
} while (this.eat(tt.comma));
|
||||
}
|
||||
|
||||
node.body = this.flowParseObjectType(isClass, false, false, isClass);
|
||||
node.body = this.flowParseObjectType({
|
||||
allowStatic: isClass,
|
||||
allowExact: false,
|
||||
allowSpread: false,
|
||||
allowProto: isClass,
|
||||
allowInexact: false,
|
||||
});
|
||||
}
|
||||
|
||||
flowParseInterfaceExtends(): N.FlowInterfaceExtends {
|
||||
@@ -484,9 +494,18 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
return this.finishNode(node, "InterfaceDeclaration");
|
||||
}
|
||||
|
||||
checkNotUnderscore(word: string) {
|
||||
if (word === "_") {
|
||||
throw this.unexpected(
|
||||
null,
|
||||
"`_` is only allowed as a type argument to call or new",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
checkReservedType(word: string, startLoc: number) {
|
||||
if (primitiveTypes.indexOf(word) > -1) {
|
||||
this.raise(startLoc, `Cannot overwrite primitive type ${word}`);
|
||||
if (reservedTypes.indexOf(word) > -1) {
|
||||
this.raise(startLoc, `Cannot overwrite reserved type ${word}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -632,12 +651,36 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
this.state.inType = true;
|
||||
|
||||
this.expectRelational("<");
|
||||
const oldNoAnonFunctionType = this.state.noAnonFunctionType;
|
||||
this.state.noAnonFunctionType = false;
|
||||
while (!this.isRelational(">")) {
|
||||
node.params.push(this.flowParseType());
|
||||
if (!this.isRelational(">")) {
|
||||
this.expect(tt.comma);
|
||||
}
|
||||
}
|
||||
this.state.noAnonFunctionType = oldNoAnonFunctionType;
|
||||
this.expectRelational(">");
|
||||
|
||||
this.state.inType = oldInType;
|
||||
|
||||
return this.finishNode(node, "TypeParameterInstantiation");
|
||||
}
|
||||
|
||||
flowParseTypeParameterInstantiationCallOrNew(): N.TypeParameterInstantiation {
|
||||
const node = this.startNode();
|
||||
const oldInType = this.state.inType;
|
||||
node.params = [];
|
||||
|
||||
this.state.inType = true;
|
||||
|
||||
this.expectRelational("<");
|
||||
while (!this.isRelational(">")) {
|
||||
node.params.push(this.flowParseTypeOrImplicitInstantiation());
|
||||
if (!this.isRelational(">")) {
|
||||
this.expect(tt.comma);
|
||||
}
|
||||
}
|
||||
this.expectRelational(">");
|
||||
|
||||
this.state.inType = oldInType;
|
||||
@@ -656,7 +699,13 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
} while (this.eat(tt.comma));
|
||||
}
|
||||
|
||||
node.body = this.flowParseObjectType(false, false, false, false);
|
||||
node.body = this.flowParseObjectType({
|
||||
allowStatic: false,
|
||||
allowExact: false,
|
||||
allowSpread: false,
|
||||
allowProto: false,
|
||||
allowInexact: false,
|
||||
});
|
||||
|
||||
return this.finishNode(node, "InterfaceTypeAnnotation");
|
||||
}
|
||||
@@ -754,12 +803,19 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
return this.finishNode(node, "ObjectTypeCallProperty");
|
||||
}
|
||||
|
||||
flowParseObjectType(
|
||||
flowParseObjectType({
|
||||
allowStatic,
|
||||
allowExact,
|
||||
allowSpread,
|
||||
allowProto,
|
||||
allowInexact,
|
||||
}: {
|
||||
allowStatic: boolean,
|
||||
allowExact: boolean,
|
||||
allowSpread: boolean,
|
||||
allowProto: boolean,
|
||||
): N.FlowObjectTypeAnnotation {
|
||||
allowInexact: boolean,
|
||||
}): N.FlowObjectTypeAnnotation {
|
||||
const oldInType = this.state.inType;
|
||||
this.state.inType = true;
|
||||
|
||||
@@ -772,6 +828,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
|
||||
let endDelim;
|
||||
let exact;
|
||||
let inexact = false;
|
||||
if (allowExact && this.match(tt.braceBarL)) {
|
||||
this.expect(tt.braceBarL);
|
||||
endDelim = tt.braceBarR;
|
||||
@@ -852,16 +909,21 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
}
|
||||
}
|
||||
|
||||
nodeStart.properties.push(
|
||||
this.flowParseObjectTypeProperty(
|
||||
node,
|
||||
isStatic,
|
||||
protoStart,
|
||||
variance,
|
||||
kind,
|
||||
allowSpread,
|
||||
),
|
||||
const propOrInexact = this.flowParseObjectTypeProperty(
|
||||
node,
|
||||
isStatic,
|
||||
protoStart,
|
||||
variance,
|
||||
kind,
|
||||
allowSpread,
|
||||
allowInexact,
|
||||
);
|
||||
|
||||
if (propOrInexact === null) {
|
||||
inexact = true;
|
||||
} else {
|
||||
nodeStart.properties.push(propOrInexact);
|
||||
}
|
||||
}
|
||||
|
||||
this.flowObjectTypeSemicolon();
|
||||
@@ -869,6 +931,15 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
|
||||
this.expect(endDelim);
|
||||
|
||||
/* The inexact flag should only be added on ObjectTypeAnnotations that
|
||||
* are not the body of an interface, declare interface, or declare class.
|
||||
* Since spreads are only allowed in objec types, checking that is
|
||||
* sufficient here.
|
||||
*/
|
||||
if (allowSpread) {
|
||||
nodeStart.inexact = inexact;
|
||||
}
|
||||
|
||||
const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
|
||||
|
||||
this.state.inType = oldInType;
|
||||
@@ -883,7 +954,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
variance: ?N.FlowVariance,
|
||||
kind: string,
|
||||
allowSpread: boolean,
|
||||
): N.FlowObjectTypeProperty | N.FlowObjectTypeSpreadProperty {
|
||||
allowInexact: boolean,
|
||||
): (N.FlowObjectTypeProperty | N.FlowObjectTypeSpreadProperty) | null {
|
||||
if (this.match(tt.ellipsis)) {
|
||||
if (!allowSpread) {
|
||||
this.unexpected(
|
||||
@@ -901,8 +973,30 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
);
|
||||
}
|
||||
this.expect(tt.ellipsis);
|
||||
node.argument = this.flowParseType();
|
||||
const isInexactToken = this.eat(tt.comma) || this.eat(tt.semi);
|
||||
|
||||
if (this.match(tt.braceR)) {
|
||||
if (allowInexact) return null;
|
||||
this.unexpected(
|
||||
null,
|
||||
"Explicit inexact syntax is only allowed inside inexact objects",
|
||||
);
|
||||
}
|
||||
|
||||
if (this.match(tt.braceBarR)) {
|
||||
this.unexpected(
|
||||
null,
|
||||
"Explicit inexact syntax cannot appear inside an explicit exact object type",
|
||||
);
|
||||
}
|
||||
|
||||
if (isInexactToken) {
|
||||
this.unexpected(
|
||||
null,
|
||||
"Explicit inexact syntax must appear at the end of an inexact object",
|
||||
);
|
||||
}
|
||||
node.argument = this.flowParseType();
|
||||
return this.finishNode(node, "ObjectTypeSpreadProperty");
|
||||
} else {
|
||||
node.key = this.flowParseObjectPropertyKey();
|
||||
@@ -1116,6 +1210,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
return this.finishNode(node, "StringTypeAnnotation");
|
||||
|
||||
default:
|
||||
this.checkNotUnderscore(id.name);
|
||||
return this.flowParseGenericType(startPos, startLoc, id);
|
||||
}
|
||||
}
|
||||
@@ -1146,10 +1241,22 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
);
|
||||
|
||||
case tt.braceL:
|
||||
return this.flowParseObjectType(false, false, true, false);
|
||||
return this.flowParseObjectType({
|
||||
allowStatic: false,
|
||||
allowExact: false,
|
||||
allowSpread: true,
|
||||
allowProto: false,
|
||||
allowInexact: true,
|
||||
});
|
||||
|
||||
case tt.braceBarL:
|
||||
return this.flowParseObjectType(false, true, true, false);
|
||||
return this.flowParseObjectType({
|
||||
allowStatic: false,
|
||||
allowExact: true,
|
||||
allowSpread: true,
|
||||
allowProto: false,
|
||||
allowInexact: false,
|
||||
});
|
||||
|
||||
case tt.bracketL:
|
||||
return this.flowParseTupleType();
|
||||
@@ -1359,6 +1466,17 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
return type;
|
||||
}
|
||||
|
||||
flowParseTypeOrImplicitInstantiation(): N.FlowTypeAnnotation {
|
||||
if (this.state.type === tt.name && this.state.value === "_") {
|
||||
const startPos = this.state.start;
|
||||
const startLoc = this.state.startLoc;
|
||||
const node = this.parseIdentifier();
|
||||
return this.flowParseGenericType(startPos, startLoc, node);
|
||||
} else {
|
||||
return this.flowParseType();
|
||||
}
|
||||
}
|
||||
|
||||
flowParseTypeAnnotation(): N.FlowTypeAnnotation {
|
||||
const node = this.startNode();
|
||||
node.typeAnnotation = this.flowParseTypeInitialiser();
|
||||
@@ -1859,40 +1977,26 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
// type casts that we've found that are illegal in this context
|
||||
toReferencedList(
|
||||
exprList: $ReadOnlyArray<?N.Expression>,
|
||||
isInParens?: boolean,
|
||||
): $ReadOnlyArray<?N.Expression> {
|
||||
for (let i = 0; i < exprList.length; i++) {
|
||||
const expr = exprList[i];
|
||||
if (expr && expr._exprListItem && expr.type === "TypeCastExpression") {
|
||||
this.raise(expr.start, "Unexpected type cast");
|
||||
if (
|
||||
expr &&
|
||||
expr.type === "TypeCastExpression" &&
|
||||
(!expr.extra || !expr.extra.parenthesized) &&
|
||||
(exprList.length > 1 || !isInParens)
|
||||
) {
|
||||
this.raise(
|
||||
expr.typeAnnotation.start,
|
||||
"The type cast expression is expected to be wrapped with parenthesis",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return exprList;
|
||||
}
|
||||
|
||||
// parse an item inside a expression list eg. `(NODE, NODE)` where NODE represents
|
||||
// the position where this function is called
|
||||
parseExprListItem(
|
||||
allowEmpty: ?boolean,
|
||||
refShorthandDefaultPos: ?Pos,
|
||||
refNeedsArrowPos: ?Pos,
|
||||
): ?N.Expression {
|
||||
const container = this.startNode();
|
||||
const node = super.parseExprListItem(
|
||||
allowEmpty,
|
||||
refShorthandDefaultPos,
|
||||
refNeedsArrowPos,
|
||||
);
|
||||
if (this.match(tt.colon)) {
|
||||
container._exprListItem = true;
|
||||
container.expression = node;
|
||||
container.typeAnnotation = this.flowParseTypeAnnotation();
|
||||
return this.finishNode(container, "TypeCastExpression");
|
||||
} else {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
checkLVal(
|
||||
expr: N.Expression,
|
||||
isBinding: ?boolean,
|
||||
@@ -2289,7 +2393,10 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
refNeedsArrowPos?: ?Pos,
|
||||
): N.Expression {
|
||||
let jsxError = null;
|
||||
if (tt.jsxTagStart && this.match(tt.jsxTagStart)) {
|
||||
if (
|
||||
this.hasPlugin("jsx") &&
|
||||
(this.match(tt.jsxTagStart) || this.isRelational("<"))
|
||||
) {
|
||||
const state = this.state.clone();
|
||||
try {
|
||||
return super.parseMaybeAssign(
|
||||
@@ -2305,7 +2412,10 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
// Remove `tc.j_expr` and `tc.j_oTag` from context added
|
||||
// by parsing `jsxTagStart` to stop the JSX plugin from
|
||||
// messing with the tokens
|
||||
this.state.context.length -= 2;
|
||||
const cLength = this.state.context.length;
|
||||
if (this.state.context[cLength - 1] === tc.j_oTag) {
|
||||
this.state.context.length -= 2;
|
||||
}
|
||||
|
||||
jsxError = err;
|
||||
} else {
|
||||
@@ -2510,7 +2620,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
node.callee = base;
|
||||
const state = this.state.clone();
|
||||
try {
|
||||
node.typeArguments = this.flowParseTypeParameterInstantiation();
|
||||
node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
|
||||
this.expect(tt.parenL);
|
||||
node.arguments = this.parseCallExpressionArguments(tt.parenR, false);
|
||||
if (subscriptState.optionalChainMember) {
|
||||
@@ -2541,7 +2651,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
if (this.shouldParseTypes() && this.isRelational("<")) {
|
||||
const state = this.state.clone();
|
||||
try {
|
||||
targs = this.flowParseTypeParameterInstantiation();
|
||||
targs = this.flowParseTypeParameterInstantiationCallOrNew();
|
||||
} catch (e) {
|
||||
if (e instanceof SyntaxError) {
|
||||
this.state = state;
|
||||
|
||||
@@ -506,6 +506,15 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
return this.parseLiteral(this.state.value, "JSXText");
|
||||
} else if (this.match(tt.jsxTagStart)) {
|
||||
return this.jsxParseElement();
|
||||
} else if (
|
||||
this.isRelational("<") &&
|
||||
this.state.input.charCodeAt(this.state.pos) !==
|
||||
charCodes.exclamationMark
|
||||
) {
|
||||
// In case we encounter an lt token here it will always be the start of
|
||||
// jsx as the lt sign is not allowed in places that expect an expression
|
||||
this.finishToken(tt.jsxTagStart);
|
||||
return this.jsxParseElement();
|
||||
} else {
|
||||
return super.parseExprAtom(refShortHandDefaultPos);
|
||||
}
|
||||
@@ -538,7 +547,12 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
}
|
||||
}
|
||||
|
||||
if (code === charCodes.lessThan && this.state.exprAllowed) {
|
||||
if (
|
||||
code === charCodes.lessThan &&
|
||||
this.state.exprAllowed &&
|
||||
this.state.input.charCodeAt(this.state.pos + 1) !==
|
||||
charCodes.exclamationMark
|
||||
) {
|
||||
++this.state.pos;
|
||||
return this.finishToken(tt.jsxTagStart);
|
||||
}
|
||||
|
||||
@@ -507,6 +507,29 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
/* bracket */ true,
|
||||
/* skipFirstToken */ false,
|
||||
);
|
||||
|
||||
// Validate the elementTypes to ensure:
|
||||
// No mandatory elements may follow optional elements
|
||||
// If there's a rest element, it must be at the end of the tuple
|
||||
let seenOptionalElement = false;
|
||||
node.elementTypes.forEach((elementNode, i) => {
|
||||
if (elementNode.type === "TSRestType") {
|
||||
if (i !== node.elementTypes.length - 1) {
|
||||
this.raise(
|
||||
elementNode.start,
|
||||
"A rest element must be last in a tuple type.",
|
||||
);
|
||||
}
|
||||
} else if (elementNode.type === "TSOptionalType") {
|
||||
seenOptionalElement = true;
|
||||
} else if (seenOptionalElement) {
|
||||
this.raise(
|
||||
elementNode.start,
|
||||
"A required element cannot follow an optional element.",
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
return this.finishNode(node, "TSTupleType");
|
||||
}
|
||||
|
||||
@@ -574,8 +597,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
const type = this.match(tt._void)
|
||||
? "TSVoidKeyword"
|
||||
: this.match(tt._null)
|
||||
? "TSNullKeyword"
|
||||
: keywordTypeFromName(this.state.value);
|
||||
? "TSNullKeyword"
|
||||
: keywordTypeFromName(this.state.value);
|
||||
if (type !== undefined && this.lookahead().type !== tt.dot) {
|
||||
const node: N.TsKeywordType = this.startNode();
|
||||
this.next();
|
||||
@@ -668,8 +691,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
return operator
|
||||
? this.tsParseTypeOperator(operator)
|
||||
: this.isContextual("infer")
|
||||
? this.tsParseInferType()
|
||||
: this.tsParseArrayTypeOrHigher();
|
||||
? this.tsParseInferType()
|
||||
: this.tsParseArrayTypeOrHigher();
|
||||
}
|
||||
|
||||
tsParseUnionOrIntersectionType(
|
||||
@@ -1358,8 +1381,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
type === "FunctionDeclaration"
|
||||
? "TSDeclareFunction"
|
||||
: type === "ClassMethod"
|
||||
? "TSDeclareMethod"
|
||||
: undefined;
|
||||
? "TSDeclareMethod"
|
||||
: undefined;
|
||||
if (bodilessType && !this.match(tt.braceL) && this.isLineTerminator()) {
|
||||
this.finishNode(node, bodilessType);
|
||||
return;
|
||||
@@ -2151,6 +2174,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
|
||||
toReferencedList(
|
||||
exprList: $ReadOnlyArray<?N.Expression>,
|
||||
isInParens?: boolean, // eslint-disable-line no-unused-vars
|
||||
): $ReadOnlyArray<?N.Expression> {
|
||||
for (let i = 0; i < exprList.length; i++) {
|
||||
const expr = exprList[i];
|
||||
|
||||
@@ -12,7 +12,7 @@ export class TokContext {
|
||||
token: string,
|
||||
isExpr?: boolean,
|
||||
preserveSpace?: boolean,
|
||||
override?: Function, // Takes a Tokenizer as a this-parameter, and returns void.
|
||||
override?: ?Function, // Takes a Tokenizer as a this-parameter, and returns void.
|
||||
) {
|
||||
this.token = token;
|
||||
this.isExpr = !!isExpr;
|
||||
@@ -31,11 +31,12 @@ export const types: {
|
||||
} = {
|
||||
braceStatement: new TokContext("{", false),
|
||||
braceExpression: new TokContext("{", true),
|
||||
templateQuasi: new TokContext("${", true),
|
||||
templateQuasi: new TokContext("${", false),
|
||||
parenStatement: new TokContext("(", false),
|
||||
parenExpression: new TokContext("(", true),
|
||||
template: new TokContext("`", true, true, p => p.readTmplToken()),
|
||||
functionExpression: new TokContext("function", true),
|
||||
functionStatement: new TokContext("function", false),
|
||||
};
|
||||
|
||||
// Token-specific context update code
|
||||
@@ -46,33 +47,26 @@ tt.parenR.updateContext = tt.braceR.updateContext = function() {
|
||||
return;
|
||||
}
|
||||
|
||||
const out = this.state.context.pop();
|
||||
if (
|
||||
out === types.braceStatement &&
|
||||
this.curContext() === types.functionExpression
|
||||
) {
|
||||
this.state.context.pop();
|
||||
this.state.exprAllowed = false;
|
||||
} else if (out === types.templateQuasi) {
|
||||
this.state.exprAllowed = true;
|
||||
} else {
|
||||
this.state.exprAllowed = !out.isExpr;
|
||||
let out = this.state.context.pop();
|
||||
if (out === types.braceStatement && this.curContext().token === "function") {
|
||||
out = this.state.context.pop();
|
||||
}
|
||||
|
||||
this.state.exprAllowed = !out.isExpr;
|
||||
};
|
||||
|
||||
tt.name.updateContext = function(prevType) {
|
||||
if (this.state.value === "of" && this.curContext() === types.parenStatement) {
|
||||
this.state.exprAllowed = !prevType.beforeExpr;
|
||||
return;
|
||||
}
|
||||
|
||||
this.state.exprAllowed = false;
|
||||
|
||||
if (prevType === tt._let || prevType === tt._const || prevType === tt._var) {
|
||||
if (lineBreak.test(this.input.slice(this.state.end))) {
|
||||
this.state.exprAllowed = true;
|
||||
let allowed = false;
|
||||
if (prevType !== tt.dot) {
|
||||
if (
|
||||
(this.state.value === "of" && !this.state.exprAllowed) ||
|
||||
(this.state.value === "yield" && this.state.inGenerator)
|
||||
) {
|
||||
allowed = true;
|
||||
}
|
||||
}
|
||||
this.state.exprAllowed = allowed;
|
||||
|
||||
if (this.state.isIterator) {
|
||||
this.state.isIterator = false;
|
||||
}
|
||||
@@ -107,8 +101,22 @@ tt.incDec.updateContext = function() {
|
||||
};
|
||||
|
||||
tt._function.updateContext = tt._class.updateContext = function(prevType) {
|
||||
if (this.state.exprAllowed && !this.braceIsBlock(prevType)) {
|
||||
if (
|
||||
prevType.beforeExpr &&
|
||||
prevType !== tt.semi &&
|
||||
prevType !== tt._else &&
|
||||
!(
|
||||
prevType === tt._return &&
|
||||
lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.start))
|
||||
) &&
|
||||
!(
|
||||
(prevType === tt.colon || prevType === tt.braceL) &&
|
||||
this.curContext() === types.b_stat
|
||||
)
|
||||
) {
|
||||
this.state.context.push(types.functionExpression);
|
||||
} else {
|
||||
this.state.context.push(types.functionStatement);
|
||||
}
|
||||
|
||||
this.state.exprAllowed = false;
|
||||
|
||||
@@ -881,10 +881,10 @@ export default class Tokenizer extends LocationParser {
|
||||
radix === 16
|
||||
? allowedNumericSeparatorSiblings.hex
|
||||
: radix === 10
|
||||
? allowedNumericSeparatorSiblings.dec
|
||||
: radix === 8
|
||||
? allowedNumericSeparatorSiblings.oct
|
||||
: allowedNumericSeparatorSiblings.bin;
|
||||
? allowedNumericSeparatorSiblings.dec
|
||||
: radix === 8
|
||||
? allowedNumericSeparatorSiblings.oct
|
||||
: allowedNumericSeparatorSiblings.bin;
|
||||
|
||||
let total = 0;
|
||||
|
||||
@@ -1070,7 +1070,6 @@ export default class Tokenizer extends LocationParser {
|
||||
readString(quote: number): void {
|
||||
let out = "",
|
||||
chunkStart = ++this.state.pos;
|
||||
const hasJsonStrings = this.hasPlugin("jsonStrings");
|
||||
for (;;) {
|
||||
if (this.state.pos >= this.input.length) {
|
||||
this.raise(this.state.start, "Unterminated string constant");
|
||||
@@ -1083,10 +1082,11 @@ export default class Tokenizer extends LocationParser {
|
||||
out += this.readEscapedChar(false);
|
||||
chunkStart = this.state.pos;
|
||||
} else if (
|
||||
hasJsonStrings &&
|
||||
(ch === charCodes.lineSeparator || ch === charCodes.paragraphSeparator)
|
||||
ch === charCodes.lineSeparator ||
|
||||
ch === charCodes.paragraphSeparator
|
||||
) {
|
||||
++this.state.pos;
|
||||
++this.state.curLine;
|
||||
} else if (isNewLine(ch)) {
|
||||
this.raise(this.state.start, "Unterminated string constant");
|
||||
} else {
|
||||
@@ -1324,14 +1324,25 @@ export default class Tokenizer extends LocationParser {
|
||||
}
|
||||
|
||||
braceIsBlock(prevType: TokenType): boolean {
|
||||
if (prevType === tt.colon) {
|
||||
const parent = this.curContext();
|
||||
if (parent === ct.braceStatement || parent === ct.braceExpression) {
|
||||
return !parent.isExpr;
|
||||
}
|
||||
const parent = this.curContext();
|
||||
if (parent === ct.functionExpression || parent === ct.functionStatement) {
|
||||
return true;
|
||||
}
|
||||
if (
|
||||
prevType === tt.colon &&
|
||||
(parent === ct.braceStatement || parent === ct.braceExpression)
|
||||
) {
|
||||
return !parent.isExpr;
|
||||
}
|
||||
|
||||
if (prevType === tt._return) {
|
||||
// The check for `tt.name && exprAllowed` detects whether we are
|
||||
// after a `yield` or `of` construct. See the `updateContext` for
|
||||
// `tt.name`.
|
||||
if (
|
||||
prevType === tt._return ||
|
||||
prevType === tt._yield ||
|
||||
(prevType === tt.name && this.state.exprAllowed)
|
||||
) {
|
||||
return lineBreak.test(
|
||||
this.input.slice(this.state.lastTokEnd, this.state.start),
|
||||
);
|
||||
@@ -1341,13 +1352,22 @@ export default class Tokenizer extends LocationParser {
|
||||
prevType === tt._else ||
|
||||
prevType === tt.semi ||
|
||||
prevType === tt.eof ||
|
||||
prevType === tt.parenR
|
||||
prevType === tt.parenR ||
|
||||
prevType === tt.arrow
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (prevType === tt.braceL) {
|
||||
return this.curContext() === ct.braceStatement;
|
||||
return parent === ct.braceStatement;
|
||||
}
|
||||
|
||||
if (
|
||||
prevType === tt._var ||
|
||||
prevType === tt._let ||
|
||||
prevType === tt._const
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (prevType === tt.relational) {
|
||||
|
||||
@@ -39,7 +39,7 @@ export default class State {
|
||||
|
||||
this.decoratorStack = [[]];
|
||||
|
||||
this.yieldInPossibleArrowParameters = null;
|
||||
this.yieldOrAwaitInPossibleArrowParameters = null;
|
||||
|
||||
this.tokens = [];
|
||||
|
||||
@@ -126,10 +126,10 @@ export default class State {
|
||||
// where @foo belongs to the outer class and @bar to the inner
|
||||
decoratorStack: Array<Array<N.Decorator>>;
|
||||
|
||||
// The first yield expression inside parenthesized expressions and arrow
|
||||
// function parameters. It is used to disallow yield in arrow function
|
||||
// parameters.
|
||||
yieldInPossibleArrowParameters: ?N.YieldExpression;
|
||||
// The first yield or await expression inside parenthesized expressions
|
||||
// and arrow function parameters. It is used to disallow yield and await in
|
||||
// arrow function parameters.
|
||||
yieldOrAwaitInPossibleArrowParameters: ?N.YieldExpression;
|
||||
|
||||
// Token store.
|
||||
tokens: Array<Token | N.Comment>;
|
||||
|
||||
@@ -174,7 +174,7 @@ export const keywords = {
|
||||
new: new KeywordTokenType("new", { beforeExpr, startsExpr }),
|
||||
this: new KeywordTokenType("this", { startsExpr }),
|
||||
super: new KeywordTokenType("super", { startsExpr }),
|
||||
class: new KeywordTokenType("class"),
|
||||
class: new KeywordTokenType("class", { startsExpr }),
|
||||
extends: new KeywordTokenType("extends", { beforeExpr }),
|
||||
export: new KeywordTokenType("export"),
|
||||
import: new KeywordTokenType("import", { startsExpr }),
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"plugins": ["objectRestSpread"]
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/es2015/for-of/brackets-const/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/es2015/for-of/brackets-const/input.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
for (const {a} of /b/) {}
|
||||
194
packages/babel-parser/test/fixtures/es2015/for-of/brackets-const/output.json
vendored
Normal file
194
packages/babel-parser/test/fixtures/es2015/for-of/brackets-const/output.json
vendored
Normal file
@@ -0,0 +1,194 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 25,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 25
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 25,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 25
|
||||
}
|
||||
},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ForOfStatement",
|
||||
"start": 0,
|
||||
"end": 25,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 25
|
||||
}
|
||||
},
|
||||
"await": false,
|
||||
"left": {
|
||||
"type": "VariableDeclaration",
|
||||
"start": 5,
|
||||
"end": 14,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 14
|
||||
}
|
||||
},
|
||||
"declarations": [
|
||||
{
|
||||
"type": "VariableDeclarator",
|
||||
"start": 11,
|
||||
"end": 14,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 11
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 14
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "ObjectPattern",
|
||||
"start": 11,
|
||||
"end": 14,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 11
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 14
|
||||
}
|
||||
},
|
||||
"properties": [
|
||||
{
|
||||
"type": "ObjectProperty",
|
||||
"start": 12,
|
||||
"end": 13,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 12
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 13
|
||||
}
|
||||
},
|
||||
"method": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start": 12,
|
||||
"end": 13,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 12
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 13
|
||||
},
|
||||
"identifierName": "a"
|
||||
},
|
||||
"name": "a"
|
||||
},
|
||||
"computed": false,
|
||||
"shorthand": true,
|
||||
"value": {
|
||||
"type": "Identifier",
|
||||
"start": 12,
|
||||
"end": 13,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 12
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 13
|
||||
},
|
||||
"identifierName": "a"
|
||||
},
|
||||
"name": "a"
|
||||
},
|
||||
"extra": {
|
||||
"shorthand": true
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"init": null
|
||||
}
|
||||
],
|
||||
"kind": "const"
|
||||
},
|
||||
"right": {
|
||||
"type": "RegExpLiteral",
|
||||
"start": 18,
|
||||
"end": 21,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 18
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 21
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"raw": "/b/"
|
||||
},
|
||||
"pattern": "b",
|
||||
"flags": ""
|
||||
},
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start": 23,
|
||||
"end": 25,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 23
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 25
|
||||
}
|
||||
},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/es2015/for-of/brackets-let/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/es2015/for-of/brackets-let/input.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
for (let {a} of /b/) {}
|
||||
194
packages/babel-parser/test/fixtures/es2015/for-of/brackets-let/output.json
vendored
Normal file
194
packages/babel-parser/test/fixtures/es2015/for-of/brackets-let/output.json
vendored
Normal file
@@ -0,0 +1,194 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 23,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 23
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 23,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 23
|
||||
}
|
||||
},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ForOfStatement",
|
||||
"start": 0,
|
||||
"end": 23,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 23
|
||||
}
|
||||
},
|
||||
"await": false,
|
||||
"left": {
|
||||
"type": "VariableDeclaration",
|
||||
"start": 5,
|
||||
"end": 12,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 12
|
||||
}
|
||||
},
|
||||
"declarations": [
|
||||
{
|
||||
"type": "VariableDeclarator",
|
||||
"start": 9,
|
||||
"end": 12,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 9
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 12
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "ObjectPattern",
|
||||
"start": 9,
|
||||
"end": 12,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 9
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 12
|
||||
}
|
||||
},
|
||||
"properties": [
|
||||
{
|
||||
"type": "ObjectProperty",
|
||||
"start": 10,
|
||||
"end": 11,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 10
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 11
|
||||
}
|
||||
},
|
||||
"method": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start": 10,
|
||||
"end": 11,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 10
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 11
|
||||
},
|
||||
"identifierName": "a"
|
||||
},
|
||||
"name": "a"
|
||||
},
|
||||
"computed": false,
|
||||
"shorthand": true,
|
||||
"value": {
|
||||
"type": "Identifier",
|
||||
"start": 10,
|
||||
"end": 11,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 10
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 11
|
||||
},
|
||||
"identifierName": "a"
|
||||
},
|
||||
"name": "a"
|
||||
},
|
||||
"extra": {
|
||||
"shorthand": true
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"init": null
|
||||
}
|
||||
],
|
||||
"kind": "let"
|
||||
},
|
||||
"right": {
|
||||
"type": "RegExpLiteral",
|
||||
"start": 16,
|
||||
"end": 19,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 16
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 19
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"raw": "/b/"
|
||||
},
|
||||
"pattern": "b",
|
||||
"flags": ""
|
||||
},
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start": 21,
|
||||
"end": 23,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 21
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 23
|
||||
}
|
||||
},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/es2015/for-of/brackets-var/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/es2015/for-of/brackets-var/input.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
for (var {a} of /b/) {}
|
||||
194
packages/babel-parser/test/fixtures/es2015/for-of/brackets-var/output.json
vendored
Normal file
194
packages/babel-parser/test/fixtures/es2015/for-of/brackets-var/output.json
vendored
Normal file
@@ -0,0 +1,194 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 23,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 23
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 23,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 23
|
||||
}
|
||||
},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ForOfStatement",
|
||||
"start": 0,
|
||||
"end": 23,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 23
|
||||
}
|
||||
},
|
||||
"await": false,
|
||||
"left": {
|
||||
"type": "VariableDeclaration",
|
||||
"start": 5,
|
||||
"end": 12,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 12
|
||||
}
|
||||
},
|
||||
"declarations": [
|
||||
{
|
||||
"type": "VariableDeclarator",
|
||||
"start": 9,
|
||||
"end": 12,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 9
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 12
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "ObjectPattern",
|
||||
"start": 9,
|
||||
"end": 12,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 9
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 12
|
||||
}
|
||||
},
|
||||
"properties": [
|
||||
{
|
||||
"type": "ObjectProperty",
|
||||
"start": 10,
|
||||
"end": 11,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 10
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 11
|
||||
}
|
||||
},
|
||||
"method": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start": 10,
|
||||
"end": 11,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 10
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 11
|
||||
},
|
||||
"identifierName": "a"
|
||||
},
|
||||
"name": "a"
|
||||
},
|
||||
"computed": false,
|
||||
"shorthand": true,
|
||||
"value": {
|
||||
"type": "Identifier",
|
||||
"start": 10,
|
||||
"end": 11,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 10
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 11
|
||||
},
|
||||
"identifierName": "a"
|
||||
},
|
||||
"name": "a"
|
||||
},
|
||||
"extra": {
|
||||
"shorthand": true
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"init": null
|
||||
}
|
||||
],
|
||||
"kind": "var"
|
||||
},
|
||||
"right": {
|
||||
"type": "RegExpLiteral",
|
||||
"start": 16,
|
||||
"end": 19,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 16
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 19
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"raw": "/b/"
|
||||
},
|
||||
"pattern": "b",
|
||||
"flags": ""
|
||||
},
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start": 21,
|
||||
"end": 23,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 21
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 23
|
||||
}
|
||||
},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
3
packages/babel-parser/test/fixtures/es2015/yield/asi2/input.js
vendored
Normal file
3
packages/babel-parser/test/fixtures/es2015/yield/asi2/input.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
function *f() { yield
|
||||
{}/1/g
|
||||
}
|
||||
172
packages/babel-parser/test/fixtures/es2015/yield/asi2/output.json
vendored
Normal file
172
packages/babel-parser/test/fixtures/es2015/yield/asi2/output.json
vendored
Normal file
@@ -0,0 +1,172 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 30,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 30,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "FunctionDeclaration",
|
||||
"start": 0,
|
||||
"end": 30,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 10,
|
||||
"end": 11,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 10
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 11
|
||||
},
|
||||
"identifierName": "f"
|
||||
},
|
||||
"name": "f"
|
||||
},
|
||||
"generator": true,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start": 14,
|
||||
"end": 30,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 14
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start": 16,
|
||||
"end": 21,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 16
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 21
|
||||
}
|
||||
},
|
||||
"expression": {
|
||||
"type": "YieldExpression",
|
||||
"start": 16,
|
||||
"end": 21,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 16
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 21
|
||||
}
|
||||
},
|
||||
"delegate": false,
|
||||
"argument": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "BlockStatement",
|
||||
"start": 22,
|
||||
"end": 24,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
}
|
||||
},
|
||||
"body": [],
|
||||
"directives": []
|
||||
},
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start": 24,
|
||||
"end": 28,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 6
|
||||
}
|
||||
},
|
||||
"expression": {
|
||||
"type": "RegExpLiteral",
|
||||
"start": 24,
|
||||
"end": 28,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 6
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"raw": "/1/g"
|
||||
},
|
||||
"pattern": "1",
|
||||
"flags": "g"
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/es2015/yield/yield class/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/es2015/yield/yield class/input.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
function* bar() { yield class {} }
|
||||
152
packages/babel-parser/test/fixtures/es2015/yield/yield class/output.json
vendored
Normal file
152
packages/babel-parser/test/fixtures/es2015/yield/yield class/output.json
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 34,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 34
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 34,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 34
|
||||
}
|
||||
},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "FunctionDeclaration",
|
||||
"start": 0,
|
||||
"end": 34,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 34
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 10,
|
||||
"end": 13,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 10
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 13
|
||||
},
|
||||
"identifierName": "bar"
|
||||
},
|
||||
"name": "bar"
|
||||
},
|
||||
"generator": true,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start": 16,
|
||||
"end": 34,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 16
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 34
|
||||
}
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start": 18,
|
||||
"end": 32,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 18
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 32
|
||||
}
|
||||
},
|
||||
"expression": {
|
||||
"type": "YieldExpression",
|
||||
"start": 18,
|
||||
"end": 32,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 18
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 32
|
||||
}
|
||||
},
|
||||
"delegate": false,
|
||||
"argument": {
|
||||
"type": "ClassExpression",
|
||||
"start": 24,
|
||||
"end": 32,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 24
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 32
|
||||
}
|
||||
},
|
||||
"id": null,
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start": 30,
|
||||
"end": 32,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 30
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 32
|
||||
}
|
||||
},
|
||||
"body": []
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user