I'm assuming these are all talking about cases that didn't already have semis:
<template>
Hello
</template>|
// ^ π«
// followed by anything
Analogous to:;
function template() {
return "Hello";
}|
// ^ π«
class Component {
<template>
Hello
</template>|
// ^ π«
}
Analogous to:
class Component {
template() {
return "Hello";
}|
// ^ π«
}
// The expression is the end of a variable declaration and followed by EOF
const HelloComponent = <template>hello</template>|
// ^ β
Analogous to:
const HelloComponent = [1]|
// ^ `;`
no-semi-mode |
---|
π« |
"Unambiguous" means that the beginning of the statement is not a valid continuation of the expression.
const HelloComponent = <template>hello</template>|
// ^ `;`
const y = 1;
Analogous to:
const HelloComponent = [1]|
// ^ `;`
const y = 1;
no-semi-mode |
---|
π« |
Ambiguity Analysis
Statements (other than ExpressionStatements
) always begin with one of:
- a keyword
var
,let
orconst
(VariableDeclaration
)if
(IfStatement
)do
(DoWhileStatement
)while
(WhileStatement
)for
(ForStatement
orForInStatement
orForOfStatement
)switch
(SwitchStatement
)continue
(ContinueStatement
)break
(BreakStatement
)return
(ReturnStatement
)try
(TryStatement
)with
(WithStatement
, but disallowed in modules)throw
(ThrowStatement
)try
(TryStatement
)debugger
(DebuggerStatement
){
(BlockStatement
)Identifier
:
(LabeledStatement
)
They can also be LabelledStatements
which are Identifier
s followed by :
.
"Ambiguous Expression" means that the next token could be the start of an expression or the continuation of the expression.
const x = <template>hello</template>|
// ^ π«
[1, 2, 3].forEach((x) => console.log(x));
Analogous to:
const x = [1, 2, 3]|
// ^ π«
[1, 2, 3].forEach((x) => console.log(x));
Or this ambiguous case, involving a regular expression.
const x = <template>hello</template>|
// ^ π«
/1/g;
Analogous to:
const x = [1, 2, 3]
// ^ π«
/1/g;
no-semi-mode |
---|
π« |
(same behavior) |
Ambiguity Analysis
In this case, we're looking for valid ways to start an expression that are also valid ways to continue an expression.
[
(ambiguousArrayLiteralExpression
)(
(ambiguousParenthesizedExpression
orArrowFunction
)/
(ambiguous withRegularExpressionLiteral
)
Unambiguous means that the beginning of the expression is not a valid continuation of the expression. It means anything that can start an expression other than the cases in the previous section.
const HelloComponent = <template>hello</template>|
// ^ `;`
await x;
Analogous to:
const HelloComponent = [1]|
// ^ `;`
await x;
no-semi-mode |
---|
π« |