Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add aliases for Standardized, TypeScript, and Flow #13666

Merged
merged 8 commits into from Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/babel-traverse/src/path/generated/asserts.ts
Expand Up @@ -328,6 +328,7 @@ export interface NodePathAssetions {
): asserts this is NodePath<t.MemberExpression>;
assertMetaProperty(opts?: object): asserts this is NodePath<t.MetaProperty>;
assertMethod(opts?: object): asserts this is NodePath<t.Method>;
assertMiscellaneous(opts?: object): asserts this is NodePath<t.Miscellaneous>;
assertMixedTypeAnnotation(
opts?: object,
): asserts this is NodePath<t.MixedTypeAnnotation>;
Expand Down Expand Up @@ -437,6 +438,7 @@ export interface NodePathAssetions {
assertSpreadProperty(
opts?: object,
): asserts this is NodePath<t.SpreadProperty>;
assertStandardized(opts?: object): asserts this is NodePath<t.Standardized>;
assertStatement(opts?: object): asserts this is NodePath<t.Statement>;
assertStaticBlock(opts?: object): asserts this is NodePath<t.StaticBlock>;
assertStringLiteral(opts?: object): asserts this is NodePath<t.StringLiteral>;
Expand Down Expand Up @@ -660,6 +662,7 @@ export interface NodePathAssetions {
assertTypeParameterInstantiation(
opts?: object,
): asserts this is NodePath<t.TypeParameterInstantiation>;
assertTypeScript(opts?: object): asserts this is NodePath<t.TypeScript>;
assertTypeofTypeAnnotation(
opts?: object,
): asserts this is NodePath<t.TypeofTypeAnnotation>;
Expand Down
3 changes: 3 additions & 0 deletions packages/babel-traverse/src/path/generated/validators.ts
Expand Up @@ -191,6 +191,7 @@ export interface NodePathValidators {
isMemberExpression(opts?: object): this is NodePath<t.MemberExpression>;
isMetaProperty(opts?: object): this is NodePath<t.MetaProperty>;
isMethod(opts?: object): this is NodePath<t.Method>;
isMiscellaneous(opts?: object): this is NodePath<t.Miscellaneous>;
isMixedTypeAnnotation(opts?: object): this is NodePath<t.MixedTypeAnnotation>;
isModuleDeclaration(opts?: object): this is NodePath<t.ModuleDeclaration>;
isModuleExpression(opts?: object): this is NodePath<t.ModuleExpression>;
Expand Down Expand Up @@ -274,6 +275,7 @@ export interface NodePathValidators {
isSequenceExpression(opts?: object): this is NodePath<t.SequenceExpression>;
isSpreadElement(opts?: object): this is NodePath<t.SpreadElement>;
isSpreadProperty(opts?: object): this is NodePath<t.SpreadProperty>;
isStandardized(opts?: object): this is NodePath<t.Standardized>;
isStatement(opts?: object): this is NodePath<t.Statement>;
isStaticBlock(opts?: object): this is NodePath<t.StaticBlock>;
isStringLiteral(opts?: object): this is NodePath<t.StringLiteral>;
Expand Down Expand Up @@ -399,6 +401,7 @@ export interface NodePathValidators {
isTypeParameterInstantiation(
opts?: object,
): this is NodePath<t.TypeParameterInstantiation>;
isTypeScript(opts?: object): this is NodePath<t.TypeScript>;
isTypeofTypeAnnotation(
opts?: object,
): this is NodePath<t.TypeofTypeAnnotation>;
Expand Down
7 changes: 6 additions & 1 deletion packages/babel-types/scripts/generators/ast-types.js
Expand Up @@ -49,7 +49,9 @@ interface BaseNode {

export type CommentTypeShorthand = "leading" | "inner" | "trailing";

export type Node = ${t.TYPES.sort().join(" | ")};\n\n`;
export type Node = ${t.TYPES.filter(k => !t.FLIPPED_ALIAS_KEYS[k])
.sort()
.join(" | ")};\n\n`;

const deprecatedAlias = {};
for (const type in t.DEPRECATED_KEYS) {
Expand Down Expand Up @@ -115,6 +117,9 @@ export interface ${deprecatedAlias[type]} extends BaseNode {
code += ` ${type}: ${type};\n`;
}
code += "}\n\n";
code += `export type DeprecatedAliases = ${Object.keys(
t.DEPRECATED_KEYS
).join(" | ")}\n\n`;

return code;
}
Expand Down
5 changes: 5 additions & 0 deletions packages/babel-types/scripts/generators/docs.js
Expand Up @@ -217,6 +217,8 @@ const aliasDescriptions = {
"A cover of [Literal](https://tc39.es/ecma262/#sec-primary-expression-literals)s, [Regular Expression Literal](https://tc39.es/ecma262/#sec-primary-expression-regular-expression-literals)s and [Template Literal](https://tc39.es/ecma262/#sec-template-literals)s.",
Loop: "A cover of loop statements.",
Method: "A cover of object methods and class methods.",
Miscellaneous:
"A cover of non-standard AST types that are sometimes useful for development.",
Copy link
Contributor

@JLHwung JLHwung Aug 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to support type Core = Exclude<t.Node, t.TypeScript | t.Flow>;, why don't we add a Core alias? The Miscellaneous type is a bit vague: you don't know what is until you have checked its containing types.

We have core.ts for the spec and experimental.ts for proposals, since core types won't become experimental, we can add Core for core.ts and CoreAndProposals for core.ts and experimental.ts.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I chose Standardized, Proposal, and StandardizedOrProposal for the aliases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot have the Proposal alias, otherwise when a proposal becomes stable we'll need a breaking change to remove it from there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @nicolo-ribaudo. I think we can start with only Standardized and TypeScript, and add more in the future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot have the Proposal alias, otherwise when a proposal becomes stable we'll need a breaking change to remove it from there.

That makes sense, I'll remove.

I think we can start with only Standardized and TypeScript, and add more in the future.

I'm gonna keep Flow, but agreed.

ModuleDeclaration:
"A cover of ImportDeclaration and [ExportDeclaration](#exportdeclaration)",
ModuleSpecifier:
Expand All @@ -233,12 +235,15 @@ const aliasDescriptions = {
"A cover of AST nodes which do not have side-effects. In other words, there is no observable behaviour changes if they are evaluated more than once.",
Scopable:
"A cover of [FunctionParent](#functionparent) and [BlockParent](#blockparent).",
Standardized:
"A cover of AST nodes which are part of an official ECMAScript specification.",
Statement:
"A cover of any [Statement](https://tc39.es/ecma262/#prod-Statement)s.",
TSBaseType: "A cover of primary TypeScript type annotations.",
TSEntityName: "A cover of ts entities.",
TSType: "A cover of TypeScript type annotations.",
TSTypeElement: "A cover of TypeScript type declarations.",
TypeScript: "A cover of AST nodes defined for TypeScript.",
Terminatorless:
"A cover of AST nodes whose semantic will change when a line terminator is inserted between the operator and the operand.",
UnaryLike: "A cover of UnaryExpression and SpreadElement.",
Expand Down
18 changes: 18 additions & 0 deletions packages/babel-types/src/asserts/generated/index.ts
Expand Up @@ -1490,6 +1490,12 @@ export function assertTSTypeParameter(
): asserts node is t.TSTypeParameter {
assert("TSTypeParameter", node, opts);
}
export function assertStandardized(
node: object | null | undefined,
opts?: object | null,
): asserts node is t.Standardized {
assert("Standardized", node, opts);
}
export function assertExpression(
node: object | null | undefined,
opts?: object | null,
Expand Down Expand Up @@ -1742,6 +1748,18 @@ export function assertJSX(
): asserts node is t.JSX {
assert("JSX", node, opts);
}
export function assertMiscellaneous(
node: object | null | undefined,
opts?: object | null,
): asserts node is t.Miscellaneous {
assert("Miscellaneous", node, opts);
}
export function assertTypeScript(
node: object | null | undefined,
opts?: object | null,
): asserts node is t.TypeScript {
assert("TypeScript", node, opts);
}
export function assertTSTypeElement(
node: object | null | undefined,
opts?: object | null,
Expand Down