ECMAScript仕様輪読会 #46
前回: ECMAScript仕様輪読会 #45
Scrapboxの招待リンク: https://scrapbox.io/projects/esspec/invitations/85b96c9fa718ce5185e307196ed8fb53
connpass: https://esspec.connpass.com/
Discord: https://discord.gg/59S3y6weQj
ES Spec Draft: https://tc39.es/ecma262/
読み物リスト
Twitter hashtag: #esspec
便利ツール
esspec-memo: https://tars0x9752.github.io/esspec-memo/esspec.html
Scrapbox Codeblock Generator: https://vzvu3k6k.github.io/scrapbox-codeblock/
TC39 Terminology: https://github.com/tc39/how-we-work/blob/main/terminology.md
時事ネタ
https://nextwebconf.connpass.com/event/300174/
https://devblogs.microsoft.com/typescript/announcing-typescript-5-3/
自己紹介 (近況報告)
syumai syumai.icon
Twitter: https://twitter.com/__syumai GitHub: https://github.com/syumai
JSConf JP面白かったです
https://www.youtube.com/@jsconfjp/streams
懇親会は行けずに残念
https://vscode.dev 面白かった
File System Access APIすごい
https://developer.mozilla.org/ja/docs/Web/API/File_System_API
https://www.chromium.org/teams/web-capabilities-fugu/
:memo: https://research.swtch.com/nih
tars0x9752 (たーず / naoki aoyama) tars0x9752.icon
nerd font をめちゃくちゃ久々にバージョンアップしたらいろいろ breaking changes が入ってて大変なことになった
polybarよさそうyebis0942.icon
https://github.com/polybar/polybar
iwatsurut
とくに、イベントもなく過ごしています。
yebis0942yebis0942.icon
JSConf JP、発表資料だけ読みました
Track Aのアーカイブは非公開っぽい
気になる: https://jsconf.jp/2023/talk/anirudh-sharma-1/
C++の仕様でECMAScriptの正規表現の仕様が一部参照されているらしい
https://en.cppreference.com/w/cpp/regex/ecmascript
仕様の再利用よさそう
GitHubのmonospaceフォント使ってみてます
https://monaspace.githubnext.com/
tars0x9752.icon monaspace kana
yebis0942.iconmonospaceなmonaspaceでした…
Texture healingすごい
OpenTypeフォントのcontextual alternatesという規格を使って隣接文字に応じて字形のバランスを調節している
20:50 再開
前回のあらすじ
今回の範囲
読み物リスト
Static Semantics: TV
TV = template value
インデックス付きのtemplate objectのコンポーネントを組み立てるために使われる
The TV of TemplateCharacter :: $ is the String value consisting of the code unit 0x0024 (DOLLAR SIGN).
$とその他の一般的な文字列は生成規則の中で別のalternativeとして定義されているので、ここでも別に記載する必要がある
TemplateCharacter :: \ NotEscapeSequence is undefined.
通常のtemplate string literalではsyntax error
code:js
\x // synatx error
tagged template literalではsynatx errorが発生しない
code:js
((s)=>s)\x // undefined
((...args) => { return console.log(args),"" })a \00 b${1}2${3}4;
[ undefined, '2', '4' , 1, 3 ] // \00 の部分が無効なので、前後の文字も含めて undefined になる
''
処理系ごとのエラーメッセージ
code:console
// V8
\09
VM100:1 Uncaught SyntaxError: Octal escape sequences are not allowed in template strings.
// SpiderMonkey
\09
Uncaught SyntaxError: octal escape sequences can't be used in untagged template literals or in strict mode code
(英語) colloquially: 口語で言うところの
Static Semantics: TRV
TRV = Template Raw Value
TVと似ているが、エスケープシーケンスはそのままの文字列としてstringになる
String.raw()っぽい
https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/raw
code:js
\x0${1}\x0${2}
\x0${1}\x0${2}
^^^^
Uncaught SyntaxError: Invalid hexadecimal escape sequence
String.raw\x0${1}\x0${2}
'\\x01\\x02'
NOTE: template stringの中の<CR>, <CR><LF>は<LF>に正規化される
Automatic Semicolon Insertion
three basic rules of semicolon insertion:
1. offending token(どんな生成規則にも一致しないトークン)が以下のルールのいずれか1つ以上に当てはまっていたら、offending tokenの直前にセミコロンを入れる
a. offending tokenと直前のトークンの間に1つ以上のLineTerminatorがある
b. offending tokenが}
c. The previous token is ) and the inserted semicolon would then be parsed as the terminating semicolon of a do-while statement (14.7.2).
2. パースできないままソースコードの終端にたどり着いたら末尾にセミコロンを入れる
3. restricted production
code:js
// 1-a
const
a
=
1
/* セミコロンが自動挿入される */console // offending token
.log(
a
)
code:js
// 1-b
if (true) { a = 1 /* セミコロンが自動挿入される */ }
() => { console.log(s) /* セミコロンが自動挿入される */ }
code:js
// 1-c
let i = 0
do {
i++
} while(i < 5) /* セミコロンが自動挿入される */ {
console.log(i)
}
code:js
// 2
console.log(1) /* セミコロンが自動挿入される */
code:js
$ cat f.js
let a = 0
a
++
$ node f.js
/Users/syumai/go/src/github.com/syumai/til/js/esspec8/f.js:4
SyntaxError: Unexpected end of input
追加の上書き条件
empty statementにはならない
空のソースコード?
Scriptは文法定義上は空でも許されるので違いそう
code:js
eval(if(true)) // Uncaught SyntaxError: expected expression, got end of script
eval(if(true);) // OK
というケースではない?yebis0942.icon
for文のセミコロンにはならない
code:js
for (let i = 0; i < 10; i++) {
console.log(i);
}
// 以下の場合は自動セミコロン挿入しない
for (
let i = 0
i < 10
i++
) {
console.log(i);
}
for (
let i = 0
;i < 10
;i++
) {
console.log(i);
}