Skip to content

Commit

Permalink
Merge branch 'master' into fix/ast-structure
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 committed Feb 22, 2021
2 parents 5177137 + 409bf0b commit ac64fe0
Show file tree
Hide file tree
Showing 10 changed files with 1,269 additions and 11 deletions.
Expand Up @@ -49,6 +49,7 @@ function getGroup(node: TSESTree.TypeNode): Group {
case AST_NODE_TYPES.TSSymbolKeyword:
case AST_NODE_TYPES.TSThisType:
case AST_NODE_TYPES.TSUnknownKeyword:
case AST_NODE_TYPES.TSIntrinsicKeyword:
return Group.keyword;

case AST_NODE_TYPES.TSNullKeyword:
Expand Down
Expand Up @@ -43,10 +43,13 @@ const valid = (operator: '|' | '&'): TSESLint.ValidTestCase<Options>[] => [
type T =
${operator} A
${operator} B
${operator} intrinsic
${operator} number[]
${operator} string[]
${operator} any
${operator} string
${operator} symbol
${operator} this
${operator} readonly number[]
${operator} readonly string[]
${operator} 'a'
Expand Down
@@ -0,0 +1,4 @@
type Uppercase<S extends string> = intrinsic;
type Lowercase<S extends string> = intrinsic;
type Capitalize<S extends string> = intrinsic;
type Uncapitalize<S extends string> = intrinsic;
1 change: 1 addition & 0 deletions packages/types/src/ast-node-types.ts
Expand Up @@ -118,6 +118,7 @@ enum AST_NODE_TYPES {
TSInterfaceDeclaration = 'TSInterfaceDeclaration',
TSInterfaceHeritage = 'TSInterfaceHeritage',
TSIntersectionType = 'TSIntersectionType',
TSIntrinsicKeyword = 'TSIntrinsicKeyword',
TSLiteralType = 'TSLiteralType',
TSMappedType = 'TSMappedType',
TSMethodSignature = 'TSMethodSignature',
Expand Down
6 changes: 6 additions & 0 deletions packages/types/src/ts-estree.ts
Expand Up @@ -249,6 +249,7 @@ export type Node =
| TSInterfaceDeclaration
| TSInterfaceHeritage
| TSIntersectionType
| TSIntrinsicKeyword
| TSLiteralType
| TSMappedType
| TSMethodSignature
Expand Down Expand Up @@ -541,6 +542,7 @@ export type TypeNode =
| TSInferType
| TSInterfaceHeritage
| TSIntersectionType
| TSIntrinsicKeyword
| TSLiteralType
| TSMappedType
| TSNamedTupleMember
Expand Down Expand Up @@ -1466,6 +1468,10 @@ export interface TSIntersectionType extends BaseNode {
types: TypeNode[];
}

export interface TSIntrinsicKeyword extends BaseNode {
type: AST_NODE_TYPES.TSIntrinsicKeyword;
}

export interface TSLiteralType extends BaseNode {
type: AST_NODE_TYPES.TSLiteralType;
literal: LiteralExpression | UnaryExpression | UpdateExpression;
Expand Down
18 changes: 7 additions & 11 deletions packages/typescript-estree/src/convert.ts
Expand Up @@ -580,13 +580,13 @@ export class Converter {
if (!modifiers || !modifiers.length) {
return;
}
const remainingModifiers: TSESTree.Modifier[] = [];
/**
* Some modifiers are explicitly handled by applying them as
* boolean values on the result node. As well as adding them
* to the result, we remove them from the array, so that they
* are not handled twice.
*/
const handledModifierIndices: { [key: number]: boolean } = {};
for (let i = 0; i < modifiers.length; i++) {
const modifier = modifiers[i];
switch (modifier.kind) {
Expand All @@ -596,31 +596,26 @@ export class Converter {
*/
case SyntaxKind.ExportKeyword:
case SyntaxKind.DefaultKeyword:
handledModifierIndices[i] = true;
break;
case SyntaxKind.ConstKeyword:
(result as any).const = true;
handledModifierIndices[i] = true;
break;
case SyntaxKind.DeclareKeyword:
result.declare = true;
handledModifierIndices[i] = true;
break;
default:
remainingModifiers.push(this.convertChild(modifier));
break;
}
}
/**
* If there are still valid modifiers available which have
* not been explicitly handled above, we just convert and
* add the modifiers array to the result node.
*/
const remainingModifiers = modifiers.filter(
(_, i) => !handledModifierIndices[i],
);
if (!remainingModifiers || !remainingModifiers.length) {
return;
if (remainingModifiers.length) {
result.modifiers = remainingModifiers;
}
result.modifiers = remainingModifiers.map(el => this.convertChild(el));
}

/**
Expand Down Expand Up @@ -2211,7 +2206,8 @@ export class Converter {
case SyntaxKind.SymbolKeyword:
case SyntaxKind.UnknownKeyword:
case SyntaxKind.VoidKeyword:
case SyntaxKind.UndefinedKeyword: {
case SyntaxKind.UndefinedKeyword:
case SyntaxKind.IntrinsicKeyword: {
return this.createNode<any>(node, {
type: AST_NODE_TYPES[`TS${SyntaxKind[node.kind]}` as AST_NODE_TYPES],
});
Expand Down
Expand Up @@ -254,6 +254,7 @@ export interface EstreeToTsNodeTypes {
[AST_NODE_TYPES.TSAnyKeyword]: ts.KeywordTypeNode;
[AST_NODE_TYPES.TSBigIntKeyword]: ts.KeywordTypeNode;
[AST_NODE_TYPES.TSBooleanKeyword]: ts.KeywordTypeNode;
[AST_NODE_TYPES.TSIntrinsicKeyword]: ts.KeywordTypeNode;
[AST_NODE_TYPES.TSNeverKeyword]: ts.KeywordTypeNode;
[AST_NODE_TYPES.TSNumberKeyword]: ts.KeywordTypeNode;
[AST_NODE_TYPES.TSObjectKeyword]: ts.KeywordTypeNode;
Expand Down
Expand Up @@ -1993,6 +1993,8 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/interface-without-type-annotation.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/intrinsic-keyword.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/keyof-operator.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/keyword-variables.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
Expand Down

0 comments on commit ac64fe0

Please sign in to comment.