Type Annotation Delimiting Concerns
Waldemar Horwat
Example
function f(a, b, c, d) {
let async = a.async;
let flag = async < 4;
if (flag) {
while (async != 10) {
d += bar(async);
++async;
}
} else {
d = -d**2;
}
return flag ? d => (d) > (c) : d => d;
}
function f(a, b, c, d) {
let async = a.async;
let flag = async < 4;
if (flag) {
while (async != 10) {
d += bar(async);
++async;
}
} else {
d = -d**2;
}
return flag ? d => (d) > (c) : d => d;
}
Syntax error
Token Soup
function f(a, b, c, d) {
let async = a.async;
let flag = async < 4;
if (flag) {
while (async != 10) {
d += bar(async);
++async;
}
} else {
d = -d**2;
}
return flag ? d => (d) > (c) : d => d;
}
CoverCallExpressionAndAsyncArrowHead : MemberExpression TypeParametersopt Arguments TypeAnnotationopt
Type-Erased Version
function f(a, b, c, d) {
let async = a.async;
let flag = async (c) => d;
}
function f(a, b, c, d) {
let async = a.async;
let flag = async < 4;
if (flag) {
while (async != 10) {
d += bar(async);
++async;
}
} else {
d = -d**2;
}
return flag ? d => (d) > (c) : d => d;
}
Discuss later
Discuss later
Token Soup
Skip arbitrary sequence of tokens, only matching:
( … ) |
[ … ] |
{ … } |
< … > |
Template literals |
Token Soup
Skip arbitrary sequence of tokens, only matching:
Unknown how / vs. /regexp/ can be handled inside Token Soup (discuss later)
( … ) |
[ … ] |
{ … } |
< … > |
Template literals |
Token Soup
function map<Input, Output>(
arr: Input[], func: (arg: Input) => Output): (Output[]) {
return arr.map(func);
}
Token Soup Delimiting
function map<Input, Output>(
arr: Input[], func: (arg: Input) => Output): (Output[]) {
return arr.map(func);
}
Can we tell whether <, [, { starts a Token Soup or some other, non-type ECMAScript syntax?
Token Soup Delimiting
function map<Input, Output>(
arr: Input[], func: (arg: Input) => Output): (Output[]) {
return arr.map(func);
}
Can we tell whether <, [, { starts a Token Soup or some other, non-type ECMAScript syntax?
Token Soup Backtracking
… {a:b} => …
Token Soup Backtracking
… {a:b} => …
… {yield / 3}; a = “4/} …
Token Soup Backtracking
… {a:b} => …
… {yield / 3}; a = “4/} …
… {yield / 3}; a = “4/} …
… {yield / 3}; a = “4/} …
Token Soup Delimiting
Can we tell whether <, [, { starts a Token Soup or some other, non-type ECMAScript syntax?
Example 1
function f(a, b, c, d) {
let async = a.async;
let flag = async < 4;
if (flag) {
while (async != 10) {
d += bar(async);
++async;
}
} else {
d = -d**2;
}
return flag ? d => (d) > (c) : d => d;
}
CoverCallExpressionAndAsyncArrowHead : MemberExpression TypeParametersopt Arguments TypeAnnotationopt
Example 1
function f(a, b, c, d) {
let foo = a.async;
let flag = foo < 4;
if (flag) {
while (foo != 10) {
d += bar(foo);
++foo;
}
} else {
d = -d**2;
}
return flag ? d => (d) > (c) : d => d;
}
CoverCallExpressionAndAsyncArrowHead : MemberExpression TypeParametersopt Arguments TypeAnnotationopt
Example 2
a : (type) => (foo())
Example 2
a : (type) => (foo())
a : (type) => (foo())
ArrowFunction :
ArrowParameters : Type => ConciseBody
Type : ParenthesizedTokens
Token Soup
CoverParenthesizedExpressionAndArrowParameterList
Example 3
a : (type) => (foo())
a : (type) => (foo()) => …
ArrowFunction :
ArrowParameters : Type => ExpressionBody
Type : ParenthesizedTokens
Type : ParenthesizedTokens =>
ParenthesizedTokens
ExpressionBody
TokenSoup
Token Soups Don’t Work
Can we tell whether <, [, { starts a Token Soup or some other, non-type ECMAScript syntax?
Token Soups Don’t Work
Can we tell whether <, [, { starts a Token Soup or some other, non-type ECMAScript syntax?
Can’t embed constant arithmetic inside Token Soups
[limit / 2]
[a < b ? a : b]
Issues filed a year ago
Extra Reserved Words
expression as type
… as (…) …
… as […] …
… as {…} …
RelationalExpression :
RelationalExpression as Type
Type : ParenthesizedTokens
Type : SquareBracketedTokens
Type : CurlyBracketedTokens
TokenSoup
Extra Reserved Words
module as {…} …
RelationalExpression :
RelationalExpression as Type
Type : ParenthesizedTokens
Type : SquareBracketedTokens
Type : CurlyBracketedTokens
ModuleDeclaration :
module Identifier { ModuleBody }
TokenSoup
ModuleBody
Divergence from TS, Flow, Hegel, …