Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upbabel-types: Add TypeScript definitions #5856
Conversation
optional: true, | ||
}, | ||
}; | ||
|
||
defineType("CallExpression", { |
This comment has been minimized.
This comment has been minimized.
@@ -279,41 +302,44 @@ defineType("FunctionExpression", { | |||
inherits: "FunctionDeclaration", | |||
aliases: ["Scopable", "Function", "BlockParent", "FunctionParent", "Expression", "Pureish"], | |||
fields: { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
andy-ms
Jun 14, 2017
Author
Contributor
It doesn't look like "inherits" merges things? opts.fields = opts.fields || inherits.fields || {};
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
andy-ms
Jun 15, 2017
Author
Contributor
A FunctionExpression can't have declare
. id
and body
are the same but I don't think it would be worth extracting those out separately.
@@ -441,22 +467,18 @@ defineType("MemberExpression", { | |||
}); | |||
|
|||
defineType("NewExpression", { |
This comment has been minimized.
This comment has been minimized.
@@ -494,8 +517,8 @@ defineType("ObjectMethod", { | |||
}, | |||
key: { | |||
validate: (function () { | |||
const normal = assertNodeType("Expression"); | |||
const computed = assertNodeType("Identifier", "StringLiteral", "NumericLiteral"); | |||
const normal = assertNodeType("Identifier", "StringLiteral", "NumericLiteral"); |
This comment has been minimized.
This comment has been minimized.
@@ -558,14 +575,12 @@ defineType("ObjectProperty", { | |||
|
|||
defineType("RestElement", { |
This comment has been minimized.
This comment has been minimized.
@@ -7,11 +7,13 @@ import defineType, { | |||
assertEach, | |||
assertOneOf, | |||
} from "./index"; | |||
import { functionCommon, patternLikeCommon } from "./core"; | |||
|
|||
defineType("AssignmentPattern", { |
This comment has been minimized.
This comment has been minimized.
@@ -26,10 +28,11 @@ defineType("AssignmentPattern", { | |||
|
|||
defineType("ArrayPattern", { |
This comment has been minimized.
This comment has been minimized.
params: { | ||
validate: chain(assertValueType("array"), assertEach(assertNodeType("LVal"))), | ||
// Unlike other functions, arrow functions are never generators. | ||
...(() => { const x = functionCommon; delete x.generator; return x; })(), |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
hzoo
Jun 14, 2017
Member
There is a proposal for arrow function generators at Stage 1 (not implemented) https://github.com/tc39/proposals
This comment has been minimized.
This comment has been minimized.
Thanks for sharing @andy-ms |
This comment has been minimized.
This comment has been minimized.
Hi @JamesHenry, I did write a validator that you can find in preview at https://github.com/andy-ms/babel/blob/typescript/packages/babel-plugin-transform-typescript/test/astUtils.js . |
This comment has been minimized.
This comment has been minimized.
codecov
bot
commented
Jun 14, 2017
•
Codecov Report
@@ Coverage Diff @@
## 7.0 #5856 +/- ##
==========================================
+ Coverage 85.25% 85.34% +0.08%
==========================================
Files 284 286 +2
Lines 9963 10030 +67
Branches 2781 2781
==========================================
+ Hits 8494 8560 +66
Misses 969 969
- Partials 500 501 +1
Continue to review full report at Codecov.
|
defineType("TSDeclareMethod", { | ||
visitor: ["decorators", "key", "typeParameters", "params", "returnType"], | ||
fields: classMethodOrDeclareMethodCommon, | ||
}); |
This comment has been minimized.
This comment has been minimized.
Jessidhia
Jun 28, 2017
Member
Are these for overload declarations, or for things that have the declare
keyword?
This comment has been minimized.
This comment has been minimized.
andy-ms
Jun 28, 2017
Author
Contributor
Could be either. It's any method with no body.
declare class C1 { // ClassDeclaration with declare: true
m(): void; // TSDeclareMethod
}
class C2 {
m(x: number): number; // TSDeclareMethod
m(x: string): string; // TSDeclareMethod
m(x: any) { return x; } // ClassMethod
}
@@ -264,30 +271,47 @@ defineType("ForStatement", { | |||
}, | |||
}); | |||
|
|||
export const functionCommon = { | |||
params: { |
This comment has been minimized.
This comment has been minimized.
hzoo
Jul 12, 2017
Member
Looks like generator got removed?
generator: {
default: false,
validate: assertValueType("boolean"),
}
@@ -118,8 +118,10 @@ defineType("BreakStatement", { | |||
aliases: ["Statement", "Terminatorless", "CompletionStatement"], | |||
}); | |||
|
|||
defineType("CallExpression", { | |||
visitor: ["callee", "arguments"], | |||
const callOrNew = { |
This comment has been minimized.
This comment has been minimized.
}, | ||
id: { | ||
validate: assertNodeType("Identifier"), | ||
optional: true, // May be null for `export default function` |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Jessidhia
Jul 14, 2017
Member
export default function () {}
should be named *default*
, which you can't really represent as a valid Identifier
:)
This comment has been minimized.
This comment has been minimized.
assertEach(assertNodeType("LVal")), | ||
), | ||
...functionCommon, | ||
expression: { |
This comment has been minimized.
This comment has been minimized.
}, | ||
id: { | ||
validate: assertNodeType("Identifier"), | ||
optional: true, // Missing if this is the child of an ExportDefaultDeclaration. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Jessidhia
Jul 14, 2017
Member
Same reason as function
. They're both special-cased in the spec to allow omitting the name specifically in this case.
awesome work again andy, sorry for the wait |
andy-ms commentedJun 13, 2017
•
edited
Companion to babel/babylon#523. This adds definitions for all of the TypeScript nodes.
I tested this by recursively validating TypeScript trees parsed from DefinitelyTyped. That script also tests the TS plugin, so I'll wait to include the script in the PR that adds the plugin.
CC @JamesHenry @soda0289 This defines the spec for TypeScript nodes, and duplicates the information found in
types.js
in babel/babylon#523.