Twitter hashtag: #esspec
便利ツール
時事ネタ
自己紹介 (近況報告)
syumai syumai.icon
Workers Tech Talksというイベントで登壇してきました
Software Design 1月号にCloudflare Workersの連載の2本目載ってます
最近は楽器をやっています
tars0x9752 (たーず / naoki aoyama) tars0x9752.icon
PC新しく組んだ
余ったパーツでLinuxマシンでも作ろうかななど
おすすめ情報: tailscale
iwatsurut
とくに、イベントもなく過ごしています。
60歳になってしまいました。ギリギリで、定年が3年伸びました。
PADAone (ぱだわん)
型の圏に興味があって最近は圏論の勉強を始めました
型システム入門の輪読会やってます
yebis0942yebis0942.icon
最近使ったセッション管理サービス
カンファレンスのセッション公募からタイムテーブル公開までできる
UI作り込んでるけどReactとか使ってなさそうでびっくりした
前回のあらすじ
[no LineTerminator here]
practical advice to ECMAScript programmers
example
今回の範囲
12.10.3 Interesting Cases of Automatic Semicolon Insertion
Interesting Cases of Automatic Semicolon Insertion
This section is non-normative.
「このセクションは規範的ではない」
= 仕様を定めるものではない
As new syntactic features are added to ECMAScript, additional grammar productions could be added that (cause lines relying on automatic semicolon insertion preceding them) to change grammar productions when parsed.
An opening parenthesis (
code:js
const a = 1 + 2
(3 + 4).toString()
/*
(3 + 4).toString()
^
TypeError: 2 is not a function
*/
An opening square bracket [
code:js
const a = 1 + 2
/*
^
TypeError: Cannot read properties of undefined (reading 'toString')
*/
const a = b
3, 4.toString() // []の中身がカンマ演算子扱いになり、4番目のindexが存在するのでOK A template literal `
code:js
const a = 1 + 2
hello
/*
hello
^
TypeError: 2 is not a function
*/
Unary + or -
code:js
const a = 1 + 2
-1
console.log(a) // 2 => -1 の部分が前の行の式の一部とみなされるため
RegExp literal /.../
code:js
const g = 3
const x = 9
const a = 27
/x/g
console.log(a) // 1 => / の部分が前の行の式の一部とみなされるため
code:js
const g = 3
const x = 9
const a = 27
/x/
console.log(a)
/*
console.log(a)
^
ReferenceError: Cannot access 'a' before initialization
*/
MultiplicativeOperator: * / %の演算子
/が正規表現リテラルの/.../と同じ文字を使っている
Cases of Automatic Semicolon Insertion and “[no LineTerminator here]”
12.10.1 Rules of Automatic Semicolon InsertionのNOTEと同じ内容
ASIのルールの覚え方?
「セミコロンを省略する場合、12.10.3.1 Interesting Cases of Automatic Semicolon Insertion in Statement Listsに列挙されているケースでは行頭にセミコロンを付けなければならない」
13 ECMAScript Language: Expressions
13.1 Identifiers
速習Grammatical Parameters
Q. Yield, Awaitなどのパラメータはどこで有効になる?
A. function *() { ... }, async () => { ... }の中で有効になる
マウスオーバーしてReferenceを辿っていくと発見できる
$ \mathit{BindingIdentifier} _{\lbrack \rm{Yield, Await} \rbrack}
この生成規則では右辺でパラメータを参照してないが、なぜパラメータが定義されている?
Early Errorsの定義でパラメータを参照していた
NOTE:
yieldとawaitがBindingIdentifierとして許されているが、static semanticsでは許可されていない
これによって次のようなケースでのASIが禁止されている code:js
let
await 0;
なぜこの場合にASIを禁止したいのか?
ASIを禁止していないとこうなる(awaitがoffending tokenとなって;が挿入される)
code:js
let;
await 0;
code:js
let; // このletはidentifierとしてパースされる(letという変数を参照してReference Errorが発生する)
code:js
await 0; // これは0と評価される(awaitにPromiseでない値を渡すとPromiseでラップされてから評価される)
ということは、ASIが適用されてしまうと以下のようになる。
code:js
var let = 1;
(async () => {
let;
await 0;
})(); // エラーにならない
code:js
var let = 1;
(async () => {
let
await 0;
})();
/*
await 0;
^^^^^
SyntaxError: Unexpected reserved word
*/
Static Semantics: Early Errors
BindingIdentifier : Identifier
strictモードでIdentifierのStringValueがargumentsまたはevalならSyntaxError
code:js
(function() {
"use strict";
let arguments = [];
})();
/*
let arguments = [];
^^^^^^^^^
SyntaxError: Unexpected eval or arguments in strict mode
*/
代入だけ禁止されているのが不思議
$ \mathit{IdentifierReference}_{\lbrack Yield, Await \rbrack} : Identifier
ここでyield, awaitをsyntax errorとしているが、その前の$ \mathit{BindingIdentifier} _{\lbrack Yield, Await \rbrack} : \tt{yield} の規則ですでに対応済みなのでは?
以下のように、ソースコード内に直接yieldなどと書かずにBindingIdentifierとしてyieldを作った場合に対応している
code:js
async () => { const \u{61}wait = 1; } // await
^^^^^^^^^^
Uncaught SyntaxError: Unexpected reserved word
Static Semantics: StringValue
Syntax Directed Operationとは
Abstact Operationの仲間
生成規則に紐付いていて、生成規則の右辺ごとに異なるアルゴリズムを持てる
the StringValue of any ReservedWord
のように書くと、「ReservedWordのSyntax Directed OperationであるStringValueの実行結果」という意味になる
引数も取れる