-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathop-policy.js
More file actions
57 lines (53 loc) · 2.61 KB
/
op-policy.js
File metadata and controls
57 lines (53 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* Shared op policy for jzify (transform) and prepare (reject).
*
* `.jz` source bypasses jzify, so prepare must enforce reject rules for both paths.
* jzify lowers `var`/`function`/`class`/`arguments` before prepare; prepare rejects
* survivors. Identifiers (`this`, `eval`, …) have no safe lowering in either pass.
*
* @module op-policy
*/
/** Ops prepare rejects when they appear in the AST (handler or identifier). */
export const REJECT_OPS = {
async: 'async/await not supported: WASM is synchronous',
await: 'async/await not supported: WASM is synchronous',
class: 'class not supported: use object literals',
yield: 'generators not supported: use loops',
instanceof: 'instanceof not supported: use typeof',
with: '`with` not supported: deprecated',
':': 'labeled statements not supported',
var: '`var` not supported: use let/const',
function: '`function` not supported: use arrow functions',
}
/** Bare identifiers prepare rejects (no jzify lowering). */
export const REJECT_IDENTS = {
with: '`with` not supported',
class: '`class` not supported',
yield: '`yield` not supported',
this: '`this` not supported: use explicit parameter',
super: '`super` not supported: no class inheritance',
arguments: '`arguments` not supported: use rest params',
eval: '`eval` not supported',
// `const` is an always-reserved word (like `class`/`with` above) — never a valid
// binding/identifier name in any mode; subscript parses it as a plain identifier,
// so reject it. NOT `let`: `let` is only *strict-mode* reserved and is a legal
// identifier in sloppy JS (`var let = 5`), so rejecting it would refuse valid JS
// (test262 language/expressions/object/let-non-strict-*).
const: '`const` is a reserved word, not a valid name',
}
/** jzify-only errors for class lowering (no prepare counterpart). */
export const JZIFY_CLASS_ERRORS = {
computedMember: 'non-constant computed class member names are not supported',
computedStaticField: 'non-constant computed static class fields are not supported',
computedField: 'non-constant computed/destructured class fields are not supported',
computedStaticMember: 'non-constant computed static class member names are not supported',
accessor: 'class getters/setters are not supported — jz objects have no accessors',
staticMember: '`static` class members are not supported yet',
superProp: '`super` property access is not supported yet',
}
/** Build prepare handler map from shared reject messages. */
export function rejectHandlers(errFn) {
const out = {}
for (const [op, msg] of Object.entries(REJECT_OPS)) out[op] = () => errFn(msg)
return out
}