[ts] Add support for the "intrinsic" keyword (#12147)

This commit is contained in:
Nicolò Ribaudo
2020-10-14 20:15:17 +02:00
committed by GitHub
parent 9c7d9c0fe5
commit 9f40d6fcd0
15 changed files with 302 additions and 2 deletions

View File

@@ -113,6 +113,7 @@ const TSErrors = Object.freeze({
});
// Doesn't handle "void" or "null" because those are keywords, not identifiers.
// It also doesn't handle "intrinsic", since usually it's not a keyword.
function keywordTypeFromName(
value: string,
): N.TsKeywordTypeType | typeof undefined {
@@ -1242,7 +1243,21 @@ export default (superClass: Class<Parser>): Class<Parser> =>
this.checkLVal(node.id, BIND_TS_TYPE, undefined, "typescript type alias");
node.typeParameters = this.tsTryParseTypeParameters();
node.typeAnnotation = this.tsExpectThenParseType(tt.eq);
node.typeAnnotation = this.tsInType(() => {
this.expect(tt.eq);
if (
this.isContextual("intrinsic") &&
this.lookahead().type !== tt.dot
) {
const node: N.TsKeywordType = this.startNode();
this.next();
return this.finishNode(node, "TSIntrinsicKeyword");
}
return this.tsParseType();
});
this.semicolon();
return this.finishNode(node, "TSTypeAliasDeclaration");
}