Add support for TS declare modifier on fields (#10545)

* [parser] Add support for TS declare modifier on fields (#10484)

* [parser] Add support for TS declare modifier on fields

* Use Object.create(null)

* Comment

* Add support for TS declare types to types and generator (#10544)

* Transform TypeScript "declare" fields (#10546)

* Transform TypeScript "declare" fields

* Remove multiple spaces

* declareFields -> allowDeclareFields

* Update after rebase
This commit is contained in:
Nicolò Ribaudo
2019-11-05 10:56:57 +01:00
committed by GitHub
parent 87feda7c2a
commit e9c1bce50f
38 changed files with 984 additions and 165 deletions

View File

@@ -5,6 +5,8 @@ import ReplaceSupers, {
import memberExpressionToFunctions from "@babel/helper-member-expression-to-functions";
import optimiseCall from "@babel/helper-optimise-call-expression";
import * as ts from "./typescript";
export function buildPrivateNamesMap(props) {
const privateNamesMap = new Map();
for (const prop of props) {
@@ -556,6 +558,8 @@ export function buildFieldsInitNodes(
let needsClassRef = false;
for (const prop of props) {
ts.assertFieldTransformed(prop);
const isStatic = prop.node.static;
const isInstance = !isStatic;
const isPrivate = prop.isPrivate();

View File

@@ -0,0 +1,19 @@
// @flow
import type { NodePath } from "@babel/traverse";
export function assertFieldTransformed(path: NodePath) {
// TODO (Babel 8): Also check path.node.definite
if (path.node.declare) {
throw path.buildCodeFrameError(
`TypeScript 'declare' fields must first be transformed by ` +
`@babel/plugin-transform-typescript.\n` +
`If you have already enabled that plugin (or '@babel/preset-typescript'), make sure ` +
`that it runs before any plugin related to additional class features:\n` +
` - @babel/plugin-proposal-class-properties\n` +
` - @babel/plugin-proposal-private-methods\n` +
` - @babel/plugin-proposal-decorators`,
);
}
}