Compare commits

...

11 Commits

Author SHA1 Message Date
Nicolò Ribaudo
21228abfde v7.2.4 2018-12-20 13:08:41 +01:00
Nicolò Ribaudo
e417437355 Minify standalone 2018-12-20 12:50:41 +01:00
Nicolò Ribaudo
0bb720401b v7.2.3 2018-12-20 12:18:31 +01:00
Nicolò Ribaudo
d35f2ad92b Update lerna to v3.6.0
Use forked @lerna/collect-updates to prevent publishing of dependents:
this is the same as Lerna 2's --dangerously-only-publish-explicit-etc option.
2018-12-20 11:46:56 +01:00
Nicolò Ribaudo
57759cb1a1 [lerna] Don't ignore .json data files in preset-env (#9200) 2018-12-20 11:43:40 +01:00
Cameron Martin
9e95da4eaa Added type-level mapping between aliases and nodes that have that alias. (#9110) 2018-12-19 10:57:27 +01:00
Nicolò Ribaudo
911c2d0bf4 Use @babel/eslint-plugin-developement (#9206) 2018-12-18 22:59:43 +01:00
cphamlet
116ca22def Minor typo for -f flag in cli (#9201) 2018-12-17 19:29:23 -08:00
Tan Li Hau
52fb884550 Strips flow directive fully (#9197) 2018-12-17 09:27:56 +01:00
Daniel Tschinder
5cb38995c0 Allow keywords to be used in type annotations (#9184) 2018-12-15 12:51:24 -08:00
Andy Edwards
3c8e15dbc1 don't throw classNameTDZError if referenced identifier is within a TypeAnnotation (#9190)
fix #9189

Obviously this code is intended to throw an error if someone tries to reference a class before it's defined, like:
```js
class Foo {
  someField = Foo;
}
```
But there's no problem with referencing the class in a type annotation before it's defined, and this is often necessary for tree structures:
```js
class Foo {
  [someSymbol]: Foo;
}
```
2018-12-15 15:16:43 +01:00
50 changed files with 2140 additions and 923 deletions

View File

@@ -1,7 +1,7 @@
{
"root": true,
"extends": "babel",
"plugins": ["local-rules", "prettier"],
"plugins": ["prettier", "@babel/development"],
"rules": {
"prettier/prettier": "error"
},
@@ -12,8 +12,8 @@
{
"files": ["packages/*/src/**/*.js", "codemods/*/src/**/*.js"],
"rules": {
"local-rules/no-undefined-identifier": "error",
"local-rules/no-deprecated-clone": "error"
"@babel/development/no-undefined-identifier": "error",
"@babel/development/no-deprecated-clone": "error"
}
},
{
@@ -31,7 +31,7 @@
"files": ["packages/babel-plugin-*/src/index.js"],
"excludedFiles": ["packages/babel-plugin-transform-regenerator/**/*.js"],
"rules": {
"local-rules/plugin-name": "error"
"@babel/development/plugin-name": "error"
}
}
]

View File

@@ -130,8 +130,7 @@ prepublish:
make test
publish: prepublish
# --only-explicit-updates
./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
./node_modules/.bin/lerna publish --force-publish="@babel/runtime,@babel/runtime-corejs2,@babel/standalone,@babel/preset-env-standalone" --require-scripts
make clean
bootstrap: clean-all

View File

@@ -1,6 +1,5 @@
{
"lerna": "2.11.0",
"version": "7.2.2",
"version": "7.2.4",
"changelog": {
"repo": "babel/babel",
"cacheDir": ".changelog",
@@ -14,21 +13,21 @@
"PR: Internal :house:": ":house: Internal"
}
},
"commands": {
"command": {
"publish": {
"ignore": [
"ignoreChanges": [
"*.md",
"*.json",
"*.txt",
"test/**",
"codemods/**",
"package.json"
"# We ignore every JSON file, except for built-in-modules, built-ins and plugins defined in babel-preset-env/data.",
"@(!(built-in-modules|built-ins|plugins)).json"
]
}
},
"packages": [
"packages/*",
"codemods/*"
"codemods/*",
"packages/*"
],
"npmClient": "yarn",
"npmClientArgs": [

View File

@@ -11,6 +11,7 @@
"devDependencies": {
"@babel/cli": "^7.2.0",
"@babel/core": "^7.2.0",
"@babel/eslint-plugin-development": "^1.0.1",
"@babel/plugin-proposal-class-properties": "^7.2.1",
"@babel/plugin-proposal-export-namespace-from": "^7.2.0",
"@babel/plugin-proposal-numeric-separator": "^7.2.0",
@@ -34,7 +35,6 @@
"eslint": "^5.9.0",
"eslint-config-babel": "^8.0.2",
"eslint-plugin-flowtype": "^3.2.0",
"eslint-plugin-local-rules": "0.1.0",
"eslint-plugin-prettier": "^3.0.0",
"flow-bin": "^0.87.0",
"graceful-fs": "^4.1.11",
@@ -49,7 +49,7 @@
"gulp-watch": "^5.0.1",
"husky": "^1.2.0",
"jest": "^23.6.0",
"lerna": "^2.11.0",
"lerna": "^3.6.0",
"lerna-changelog": "^0.5.0",
"lint-staged": "^8.1.0",
"lodash": "^4.17.10",
@@ -69,6 +69,9 @@
"webpack-dependency-suite": "^2.4.4",
"webpack-stream": "^4.0.0"
},
"resolutions": {
"@lerna/**/@lerna/collect-updates": "https://github.com/nicolo-ribaudo/lerna.git#babel-collect-updates"
},
"engines": {
"node": ">= 6.9.0 < 12.0.0",
"npm": ">= 3.x <= 6.x",

View File

@@ -1,6 +1,6 @@
{
"name": "@babel/cli",
"version": "7.2.0",
"version": "7.2.3",
"description": "Babel command line.",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",

View File

@@ -22,7 +22,7 @@ commander.option(
"comma-separated list of plugin names",
collect,
);
commander.option("--config-file [path]", "Path a to .babelrc file to use");
commander.option("--config-file [path]", "Path to a .babelrc file to use");
commander.option(
"--env-name [name]",
"The name of the 'env' to use when loading configs and plugins. " +

View File

@@ -1,6 +1,6 @@
{
"name": "@babel/helper-create-class-features-plugin",
"version": "7.2.2",
"version": "7.2.3",
"author": "The Babel Team (https://babeljs.io/team)",
"license": "MIT",
"description": "Compile class public and private fields, private methods and decorators to ES6",
@@ -18,7 +18,7 @@
"@babel/helper-member-expression-to-functions": "^7.0.0",
"@babel/helper-optimise-call-expression": "^7.0.0",
"@babel/helper-plugin-utils": "^7.0.0",
"@babel/helper-replace-supers": "^7.1.0"
"@babel/helper-replace-supers": "^7.2.3"
},
"peerDependencies": {
"@babel/core": "^7.0.0"

View File

@@ -0,0 +1,7 @@
const sym = Symbol();
const sym1 = Symbol();
class A {
[sym]: A.B;
[sym1]: Array<A>;
}

View File

@@ -0,0 +1,8 @@
{
"presets": [
"flow"
],
"plugins": [
"proposal-class-properties"
]
}

View File

@@ -0,0 +1,13 @@
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
const sym = Symbol();
const sym1 = Symbol();
class A {
constructor() {
_defineProperty(this, sym, void 0);
_defineProperty(this, sym1, void 0);
}
}

View File

@@ -0,0 +1,5 @@
const sym = Symbol();
class A {
[sym]: A;
}

View File

@@ -0,0 +1,8 @@
{
"presets": [
"flow"
],
"plugins": [
"proposal-class-properties"
]
}

View File

@@ -0,0 +1,10 @@
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
const sym = Symbol();
class A {
constructor() {
_defineProperty(this, sym, void 0);
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "@babel/helper-replace-supers",
"version": "7.1.0",
"version": "7.2.3",
"description": "Helper function to replace supers",
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-replace-supers",
"license": "MIT",
@@ -11,7 +11,7 @@
"dependencies": {
"@babel/helper-member-expression-to-functions": "^7.0.0",
"@babel/helper-optimise-call-expression": "^7.0.0",
"@babel/traverse": "^7.1.0",
"@babel/traverse": "^7.2.3",
"@babel/types": "^7.0.0"
}
}

View File

@@ -40,6 +40,9 @@ function skipAllButComputedKey(path) {
}
export const environmentVisitor = {
TypeAnnotation(path) {
path.skip();
},
Function(path) {
// Methods will be handled by the Method visit
if (path.isMethod()) return;

View File

@@ -1,6 +1,6 @@
{
"name": "@babel/parser",
"version": "7.2.2",
"version": "7.2.3",
"description": "A JavaScript parser",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",

View File

@@ -1384,6 +1384,10 @@ export default (superClass: Class<Parser>): Class<Parser> =>
default:
if (this.state.type.keyword === "typeof") {
return this.flowParseTypeofType();
} else if (this.state.type.keyword) {
const label = this.state.type.label;
this.next();
return super.createIdentifier(node, label);
}
}

View File

@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:23)"
"throws": "Unexpected token, expected \";\" (1:27)"
}

View File

@@ -0,0 +1 @@
function foo(a:function) {}

View File

@@ -0,0 +1,137 @@
{
"type": "File",
"start": 0,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 27
}
},
"program": {
"type": "Program",
"start": 0,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 27
}
},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "FunctionDeclaration",
"start": 0,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 27
}
},
"id": {
"type": "Identifier",
"start": 9,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 12
},
"identifierName": "foo"
},
"name": "foo"
},
"generator": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 13,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 23
},
"identifierName": "a"
},
"name": "a",
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 14,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 23
}
},
"typeAnnotation": {
"type": "Identifier",
"start": 15,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 23
},
"identifierName": "function"
},
"name": "function"
}
}
}
],
"body": {
"type": "BlockStatement",
"start": 25,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 25
},
"end": {
"line": 1,
"column": 27
}
},
"body": [],
"directives": []
}
}
],
"directives": []
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "@babel/plugin-proposal-class-properties",
"version": "7.2.1",
"version": "7.2.3",
"description": "This plugin transforms static class properties as well as properties declared with the property initializer syntax",
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-proposal-class-properties",
"license": "MIT",
@@ -12,7 +12,7 @@
"babel-plugin"
],
"dependencies": {
"@babel/helper-create-class-features-plugin": "^7.2.1",
"@babel/helper-create-class-features-plugin": "^7.2.3",
"@babel/helper-plugin-utils": "^7.0.0"
},
"peerDependencies": {

View File

@@ -1,4 +1,4 @@
/* eslint-disable local-rules/plugin-name */
/* eslint-disable @babel/development/plugin-name */
import { declare } from "@babel/helper-plugin-utils";
import {

View File

@@ -1,6 +1,6 @@
{
"name": "@babel/plugin-proposal-decorators",
"version": "7.2.2",
"version": "7.2.3",
"author": "Logan Smyth <loganfsmyth@gmail.com>",
"license": "MIT",
"publishConfig": {
@@ -15,7 +15,7 @@
"decorators"
],
"dependencies": {
"@babel/helper-create-class-features-plugin": "^7.2.2",
"@babel/helper-create-class-features-plugin": "^7.2.3",
"@babel/helper-plugin-utils": "^7.0.0",
"@babel/plugin-syntax-decorators": "^7.2.0"
},

View File

@@ -1,4 +1,4 @@
/* eslint-disable local-rules/plugin-name */
/* eslint-disable @babel/development/plugin-name */
import { declare } from "@babel/helper-plugin-utils";
import syntaxDecorators from "@babel/plugin-syntax-decorators";

View File

@@ -1,6 +1,6 @@
{
"name": "@babel/plugin-proposal-private-methods",
"version": "7.2.1",
"version": "7.2.3",
"description": "This plugin transforms private class methods",
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-proposal-private-methods",
"license": "MIT",
@@ -12,7 +12,7 @@
"babel-plugin"
],
"dependencies": {
"@babel/helper-create-class-features-plugin": "^7.2.1",
"@babel/helper-create-class-features-plugin": "^7.2.3",
"@babel/helper-plugin-utils": "^7.0.0"
},
"peerDependencies": {

View File

@@ -1,4 +1,4 @@
/* eslint-disable local-rules/plugin-name */
/* eslint-disable @babel/development/plugin-name */
import { declare } from "@babel/helper-plugin-utils";
import {

View File

@@ -1,6 +1,6 @@
{
"name": "@babel/plugin-transform-flow-strip-types",
"version": "7.2.0",
"version": "7.2.3",
"description": "Strip flow type annotations from your output code.",
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-flow-strip-types",
"license": "MIT",

View File

@@ -5,7 +5,7 @@ import { types as t } from "@babel/core";
export default declare(api => {
api.assertVersion(7);
const FLOW_DIRECTIVE = "@flow";
const FLOW_DIRECTIVE = /(@flow(\s+(strict(-local)?|weak))?|@noflow)/;
let skipStrip = false;
@@ -28,7 +28,7 @@ export default declare(api => {
if (comments) {
for (const comment of (comments: Array<Object>)) {
if (comment.value.indexOf(FLOW_DIRECTIVE) >= 0) {
if (FLOW_DIRECTIVE.test(comment.value)) {
directiveFound = true;
// remove flow directive

View File

@@ -0,0 +1,2 @@
// @noflow
const a = 1;

View File

@@ -0,0 +1,2 @@
// @flow strict-local
const a = 1;

View File

@@ -0,0 +1,2 @@
// @flow strict
const a = 1;

View File

@@ -0,0 +1,2 @@
// @flow weak
const a = 1;

View File

@@ -1,6 +1,6 @@
{
"name": "@babel/polyfill",
"version": "7.0.0",
"version": "7.2.3",
"description": "Provides polyfills necessary for a full ES2015+ environment",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",

View File

@@ -1,6 +1,6 @@
{
"name": "@babel/preset-env-standalone",
"version": "7.2.2",
"version": "7.2.4",
"description": "Standalone build of babel-prest-env for use in non-Node.js environments.",
"main": "babel-preset-env.js",
"files": [
@@ -11,8 +11,8 @@
"devDependencies": {
"@babel/plugin-proposal-json-strings": "^7.0.0",
"@babel/plugin-transform-new-target": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/standalone": "^7.2.2"
"@babel/preset-env": "^7.2.3",
"@babel/standalone": "^7.2.4"
},
"keywords": [
"babel",

View File

@@ -1,6 +1,6 @@
{
"name": "@babel/preset-env",
"version": "7.2.0",
"version": "7.2.3",
"description": "A Babel preset for each environment.",
"author": "Henry Zhu <hi@henryzoo.com>",
"homepage": "https://babeljs.io/",
@@ -60,7 +60,7 @@
"@babel/core": "^7.0.0-0"
},
"devDependencies": {
"@babel/cli": "^7.2.0",
"@babel/cli": "^7.2.3",
"@babel/core": "^7.2.0",
"@babel/helper-fixtures": "^7.2.0",
"@babel/helper-plugin-test-runner": "^7.0.0",

View File

@@ -1,6 +1,6 @@
{
"name": "@babel/standalone",
"version": "7.2.2",
"version": "7.2.4",
"description": "Standalone build of Babel for use in non-Node.js environments.",
"main": "babel.js",
"files": [
@@ -13,8 +13,8 @@
"@babel/helper-plugin-utils": "^7.0.0",
"@babel/plugin-external-helpers": "^7.2.0",
"@babel/plugin-proposal-async-generator-functions": "^7.2.0",
"@babel/plugin-proposal-class-properties": "^7.2.0",
"@babel/plugin-proposal-decorators": "^7.2.2",
"@babel/plugin-proposal-class-properties": "^7.2.3",
"@babel/plugin-proposal-decorators": "^7.2.3",
"@babel/plugin-proposal-do-expressions": "^7.2.0",
"@babel/plugin-proposal-export-default-from": "^7.2.0",
"@babel/plugin-proposal-export-namespace-from": "^7.2.0",
@@ -27,7 +27,7 @@
"@babel/plugin-proposal-optional-catch-binding": "^7.2.0",
"@babel/plugin-proposal-optional-chaining": "^7.2.0",
"@babel/plugin-proposal-pipeline-operator": "^7.2.0",
"@babel/plugin-proposal-private-methods": "^7.2.0",
"@babel/plugin-proposal-private-methods": "^7.2.3",
"@babel/plugin-proposal-throw-expressions": "^7.2.0",
"@babel/plugin-proposal-unicode-property-regex": "^7.2.0",
"@babel/plugin-syntax-async-generators": "^7.2.0",
@@ -57,7 +57,7 @@
"@babel/plugin-transform-duplicate-keys": "^7.2.0",
"@babel/plugin-transform-exponentiation-operator": "^7.2.0",
"@babel/plugin-transform-flow-comments": "^7.2.0",
"@babel/plugin-transform-flow-strip-types": "^7.2.0",
"@babel/plugin-transform-flow-strip-types": "^7.2.3",
"@babel/plugin-transform-for-of": "^7.2.0",
"@babel/plugin-transform-function-name": "^7.2.0",
"@babel/plugin-transform-instanceof": "^7.2.0",

View File

@@ -1,6 +1,6 @@
{
"name": "@babel/traverse",
"version": "7.2.2",
"version": "7.2.3",
"description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
@@ -15,7 +15,7 @@
"@babel/generator": "^7.2.2",
"@babel/helper-function-name": "^7.1.0",
"@babel/helper-split-export-declaration": "^7.0.0",
"@babel/parser": "^7.2.2",
"@babel/parser": "^7.2.3",
"@babel/types": "^7.2.2",
"debug": "^4.1.0",
"globals": "^11.1.0",

View File

@@ -497,6 +497,7 @@ export default class Scope {
if (this.hasBinding("undefined")) {
return t.unaryExpression("void", t.numericLiteral(0), true);
} else {
// eslint-disable-next-line @babel/development/no-undefined-identifier
return t.identifier("undefined");
}
}

View File

@@ -1,104 +0,0 @@
// @flow
"use strict";
const getReferenceOrigin = require("./utils/get-reference-origin");
function reportError(context /*: Context */, node /*: Node */) {
const isMemberExpression = node.type === "MemberExpression";
const id = isMemberExpression ? node.property : node;
context.report({
node: id,
message: `t.${id.name}() is deprecated. Use t.cloneNode() instead.`,
fix(fixer) {
if (isMemberExpression) {
return fixer.replaceText(id, "cloneNode");
}
},
});
}
module.exports = {
meta: {
schema: [],
fixable: "code",
},
create(context /*: Context */) {
return {
CallExpression(node /*: Node */) {
const origin = getReferenceOrigin(node.callee, context.getScope());
if (!origin) return;
if (
origin.kind === "import" &&
(origin.name === "clone" || origin.name === "cloneDeep") &&
origin.source === "@babel/types"
) {
// imported from @babel/types
return reportError(context, node.callee);
}
if (
origin.kind === "property" &&
(origin.path === "clone" || origin.path === "cloneDeep") &&
origin.base.kind === "import" &&
origin.base.name === "types" &&
origin.base.source === "@babel/core"
) {
// imported from @babel/core
return reportError(context, node.callee);
}
if (
origin.kind === "property" &&
(origin.path === "types.clone" ||
origin.path === "types.cloneDeep") &&
origin.base.kind === "export param" &&
(origin.base.exportName === "default" ||
origin.base.exportName === "module.exports") &&
origin.base.index === 0
) {
// export default function ({ types: t }) {}
// module.exports = function ({ types: t }) {}
return reportError(context, node.callee);
}
},
};
},
};
/*:: // ESLint types
type Node = { type: string, [string]: any };
type Definition = {
type: "ImportedBinding",
name: Node,
node: Node,
parent: Node,
};
type Variable = {
defs: Definition[],
};
type Scope = {
set: Map<string, Variable>,
upper: ?Scope,
};
type Context = {
report(options: {
node: Node,
message: string,
fix?: (fixer: Fixer) => ?Fixer,
}): void,
getScope(): Scope,
};
type Fixer = {
replaceText(node: Node, replacement: string): Fixer,
};
*/

View File

@@ -1,46 +0,0 @@
"use strict";
function argumentsIsUndefinedString(argumentsArray) {
return (
argumentsArray.length === 1 &&
argumentsArray[0].type === "Literal" &&
argumentsArray[0].value === "undefined"
);
}
module.exports = {
meta: {
schema: [],
},
create: function(context) {
if (context.getFilename().indexOf("packages/babel-plugin-") === -1) {
return {};
}
return {
CallExpression: function(node) {
const callee = node.callee;
if (
callee.type === "MemberExpression" &&
argumentsIsUndefinedString(node.arguments)
) {
const object = callee.object,
property = callee.property;
if (
object.type === "Identifier" &&
object.name === "t" &&
property.type === "Identifier" &&
property.name === "identifier"
) {
context.report(
node,
"Use path.scope.buildUndefinedNode() to create an undefined identifier directly."
);
}
}
},
};
},
};

View File

@@ -1,62 +0,0 @@
"use strict";
const getReferenceOrigin = require("./utils/get-reference-origin");
function reportNoPlugin(context /*: Context */, node /*: Node */) {
context.report({
node,
message: "This file does not export a Babel plugin",
});
}
function is(type /*: string */) /*: (node: Node) => boolean */ {
return node => node.type === type;
}
module.exports = {
meta: {
schema: [],
},
create(context /*: Context */) {
return {
Program(program /*: Node */) {
if (!program.body.some(is("ExportDefaultDeclaration"))) {
return reportNoPlugin(context, program);
}
},
ExportDefaultDeclaration(exportDefaultDecl) {
let plugin = exportDefaultDecl.declaration;
if (plugin.type === "CallExpression") {
// export default declare(api => { ... });
const origin = getReferenceOrigin(plugin.callee, context.getScope());
if (
origin &&
origin.kind === "import" &&
origin.name === "declare" &&
origin.source === "@babel/helper-plugin-utils"
) {
plugin = plugin.arguments[0];
}
}
if (!plugin.type.includes("Function")) {
return reportNoPlugin(context, exportDefaultDecl.parent);
}
const returnNode = plugin.body.body.find(is("ReturnStatement"));
if (!returnNode || returnNode.argument.type !== "ObjectExpression") {
return reportNoPlugin(context, exportDefaultDecl.parent);
}
if (!returnNode.argument.properties.some(p => p.key.name === "name")) {
context.report(
returnNode,
"This Babel plugin doesn't have a 'name' property."
);
}
},
};
},
};

View File

@@ -1,34 +0,0 @@
/*:: // ESLint types
type Node = { type: string, [string]: any };
type Definition = {
type: "ImportedBinding",
name: Node,
node: Node,
parent: Node,
};
type Variable = {
defs: Definition[],
};
type Scope = {
set: Map<string, Variable>,
upper: ?Scope,
};
type Context = {
report(options: {
node: Node,
message: string,
fix?: (fixer: Fixer) => ?Fixer,
}): void,
getScope(): Scope,
};
type Fixer = {
replaceText(node: Node, replacement: string): Fixer,
};
*/

View File

@@ -1,166 +0,0 @@
"use strict";
module.exports = getReferenceOrigin;
/*::
type ReferenceOriginImport = { kind: "import", source: string, name: string };
type ReferenceOriginParam = {
kind: "export param",
exportName: string,
index: number,
};
type ReferenceOrigin =
| ReferenceOriginImport
| ReferenceOriginParam
| { kind: "import *", source: string }
| {
kind: "property",
base: ReferenceOriginImport | ReferenceOriginParam,
path: string,
};
*/
// Given a node and a context, returns a description of where its value comes
// from.
// It resolves imports, parameters of exported functions and property accesses.
// See the ReferenceOrigin type for more informations.
function getReferenceOrigin(
node /*: Node */,
scope /*: Scope */
) /*: ?ReferenceOrigin */ {
if (node.type === "Identifier") {
const variable = getVariableDefinition(node.name, scope);
if (!variable) return null;
const definition = variable.definition;
const defNode = definition.node;
if (definition.type === "ImportBinding") {
if (defNode.type === "ImportSpecifier") {
return {
kind: "import",
source: definition.parent.source.value,
name: defNode.imported.name,
};
}
if (defNode.type === "ImportNamespaceSpecifier") {
return {
kind: "import *",
source: definition.parent.source.value,
};
}
}
if (definition.type === "Variable" && defNode.init) {
const origin = getReferenceOrigin(defNode.init, variable.scope);
return origin && patternToProperty(definition.name, origin);
}
if (definition.type === "Parameter") {
const parent = defNode.parent;
let exportName /*: string */;
if (parent.type === "ExportDefaultDeclaration") {
exportName = "default";
} else if (parent.type === "ExportNamedDeclaration") {
exportName = defNode.id.name;
} else if (
parent.type === "AssignmentExpression" &&
parent.left.type === "MemberExpression" &&
parent.left.object.type === "Identifier" &&
parent.left.object.name === "module" &&
parent.left.property.type === "Identifier" &&
parent.left.property.name === "exports"
) {
exportName = "module.exports";
} else {
return null;
}
return patternToProperty(definition.name, {
kind: "export param",
exportName,
index: definition.index,
});
}
}
if (node.type === "MemberExpression" && !node.computed) {
const origin = getReferenceOrigin(node.object, scope);
return origin && addProperty(origin, node.property.name);
}
return null;
}
function getVariableDefinition(name /*: string */, scope /*: Scope */) {
let currentScope = scope;
do {
const variable = currentScope.set.get(name);
if (variable && variable.defs[0]) {
return { scope: currentScope, definition: variable.defs[0] };
}
} while ((currentScope = currentScope.upper));
}
function patternToProperty(
id /*: Node */,
base /*: ReferenceOrigin */
) /*: ?ReferenceOrigin */ {
const path = getPatternPath(id);
return path && path.reduce(addProperty, base);
}
// Adds a property to a given origin. If it was a namespace import it becomes
// a named import, so that `import * as x from "foo"; x.bar` and
// `import { bar } from "foo"` have the same origin.
function addProperty(
origin /*: ReferenceOrigin */,
name /*: string */
) /* ReferenceOrigin */ {
if (origin.kind === "import *") {
return {
kind: "import",
source: origin.source,
name,
};
}
if (origin.kind === "property") {
return {
kind: "property",
base: origin.base,
path: origin.path + "." + name,
};
}
return {
kind: "property",
base: origin,
path: name,
};
}
// if "node" is c of { a: { b: c } }, the result is ["a","b"]
function getPatternPath(node /*: Node */) /*: ?string[] */ {
let current = node;
const path = [];
// Unshift keys to path while going up
do {
const property = current.parent;
if (
property.type === "ArrayPattern" ||
property.type === "AssignmentPattern" ||
property.computed
) {
// These nodes are not supported.
return null;
}
if (property.type === "Property") {
path.unshift(property.key.name);
} else {
// The destructuring pattern is finished
break;
}
} while ((current = current.parent.parent));
return path;
}

View File

@@ -160,6 +160,13 @@ for (const type in t.FLIPPED_ALIAS_KEYS) {
.map(type => `${type}`)
.join(" | ")};\n`;
}
code += "\n";
code += "export interface Aliases {\n";
for (const type in t.FLIPPED_ALIAS_KEYS) {
code += ` ${type}: ${type};\n`;
}
code += "}\n\n";
code += lines.join("\n") + "\n";

View File

@@ -26,7 +26,6 @@ decorators/migrated_0003.js
decorators/migrated_0007.js
private_class_properties/multiple.js
private_class_properties/super.js
types/annotations/migrated_0001.js
types/annotations/void_is_reserved_param.js
types/member/reserved_words.js
types/parameter_defaults/migrated_0032.js
@@ -37,4 +36,3 @@ numbers/underscored_float_whole.js
numbers/underscored_hex.js
numbers/underscored_number.js
numbers/underscored_oct.js
types/annotations_in_comments/migrated_0001.js

2334
yarn.lock

File diff suppressed because it is too large Load Diff