TypeScript 4.1: intrinsic keyword (#1193)

Co-authored-by: 강동윤 <kdy1997.dev@gmail.com>
This commit is contained in:
Pig Fang 2020-10-29 17:37:22 +08:00 committed by GitHub
parent 5ef993d9b2
commit 11dbc1406c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 65 additions and 3 deletions

View File

@ -7,7 +7,7 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc_atoms"
repository = "https://github.com/swc-project/swc.git"
version = "0.2.4"
version = "0.2.5"
[dependencies]
string_cache = "0.8"

View File

@ -620,6 +620,7 @@ in
infer
instanceof
interface
intrinsic
is
iterator
key

View File

@ -382,6 +382,9 @@ pub enum TsKeywordTypeKind {
#[serde(rename = "never")]
TsNeverKeyword,
#[serde(rename = "intrinsic")]
TsIntrinsicKeyword,
}
#[ast_node("TsThisType")]

View File

@ -347,6 +347,7 @@ impl<'a> Emitter<'a> {
TsKeywordTypeKind::TsUndefinedKeyword => keyword!(n.span, "undefined"),
TsKeywordTypeKind::TsNullKeyword => keyword!(n.span, "null"),
TsKeywordTypeKind::TsNeverKeyword => keyword!(n.span, "never"),
TsKeywordTypeKind::TsIntrinsicKeyword => keyword!(n.span, "intrinsic"),
}
}

View File

@ -323,6 +323,9 @@ macro_rules! tok {
("bigint") => {
crate::token::Token::Word(crate::token::Word::Ident(swc_atoms::js_word!("bigint")))
};
("intrinsic") => {
crate::token::Token::Word(crate::token::Word::Ident(swc_atoms::js_word!("intrinsic")))
};
("never") => {
crate::token::Token::Word(crate::token::Word::Ident(swc_atoms::js_word!("never")))
};

View File

@ -881,7 +881,8 @@ impl<I: Tokens> Parser<I> {
| js_word!("bigint")
| js_word!("symbol")
| js_word!("void")
| js_word!("never") => {
| js_word!("never")
| js_word!("intrinsic") => {
self.emit_err(id.span, SyntaxError::TS2427);
}
_ => {}
@ -1773,6 +1774,8 @@ impl<I: Tokens> Parser<I> {
Some(TsKeywordTypeKind::TsUnknownKeyword)
} else if is!("undefined") {
Some(TsKeywordTypeKind::TsUndefinedKeyword)
} else if is!("intrinsic") {
Some(TsKeywordTypeKind::TsIntrinsicKeyword)
} else {
None
};

View File

@ -10,3 +10,4 @@ let sy: symbol;
let u: undefined;
let v: void;
let n: bigint;
let i: intrinsic;

View File

@ -2,7 +2,7 @@
"type": "Script",
"span": {
"start": 0,
"end": 184,
"end": 202,
"ctxt": 0
},
"body": [
@ -593,6 +593,55 @@
"definite": false
}
]
},
{
"type": "VariableDeclaration",
"span": {
"start": 185,
"end": 202,
"ctxt": 0
},
"kind": "let",
"declare": false,
"declarations": [
{
"type": "VariableDeclarator",
"span": {
"start": 189,
"end": 201,
"ctxt": 0
},
"id": {
"type": "Identifier",
"span": {
"start": 189,
"end": 190,
"ctxt": 0
},
"value": "i",
"typeAnnotation": {
"type": "TsTypeAnnotation",
"span": {
"start": 190,
"end": 201,
"ctxt": 0
},
"typeAnnotation": {
"type": "TsKeywordType",
"span": {
"start": 192,
"end": 201,
"ctxt": 0
},
"kind": "intrinsic"
}
},
"optional": false
},
"init": null,
"definite": false
}
]
}
],
"interpreter": null

View File

@ -1394,6 +1394,7 @@ define!({
TsUndefinedKeyword,
TsNullKeyword,
TsNeverKeyword,
TsIntrinsicKeyword,
}
pub struct TsThisType {
pub span: Span,