Skip to content

Commit 7cd8d5b

Browse files
committed
Fix repl
1 parent 336de15 commit 7cd8d5b

File tree

2 files changed

+23
-36
lines changed

2 files changed

+23
-36
lines changed

index.html

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -355,16 +355,13 @@ <h1><a href="https://github.com/dy/subscript" class="logo-link" target="_blank"
355355
unit: 'feature/unit.js',
356356

357357
// Control flow (from jessie.js)
358-
block: 'feature/block.js',
359358
'if': 'feature/if.js',
360359
loop: 'feature/loop.js',
361360
'var': 'feature/var.js',
362361
'switch': 'feature/switch.js',
363-
destruct: 'feature/destruct.js',
364362
'function': 'feature/function.js',
365363
'throw': 'feature/try.js', // throw is part of try.js
366364
'try': 'feature/try.js',
367-
control: 'feature/control.js', // BREAK, CONTINUE, RETURN symbols
368365
accessor: 'feature/accessor.js',
369366
async: 'feature/async.js',
370367
'class': 'feature/class.js',
@@ -379,7 +376,7 @@ <h1><a href="https://github.com/dy/subscript" class="logo-link" target="_blank"
379376
// Operators - order matters for token chain
380377
'assign', 'logical', 'bit', 'cmp', 'equality', 'arithmetic', 'increment',
381378
// Control flow foundations (needed by group via loop)
382-
'control', 'block', 'destruct', 'loop',
379+
'loop',
383380
// Expression features
384381
'seq', 'group', 'access',
385382
// Justin additions
@@ -397,7 +394,7 @@ <h1><a href="https://github.com/dy/subscript" class="logo-link" target="_blank"
397394
{ cat: 'Operators', items: ['assign', 'arithmetic', 'logical', 'bit', 'cmp', 'equality', 'increment', 'pow'] },
398395
{ cat: 'Advanced Ops', items: ['ternary', 'arrow', 'optional', 'spread', 'unary', 'identity', 'nullish'] },
399396
{ cat: 'Literals', items: ['literal', 'collection', 'template', 'regex', 'unit', 'comment'] },
400-
{ cat: 'Control', items: ['block', 'if', 'loop', 'switch', 'var', 'destruct', 'try'] },
397+
{ cat: 'Control', items: ['if', 'loop', 'switch', 'var', 'try'] },
401398
{ cat: 'Functions', items: ['function', 'async', 'class', 'accessor', 'module', 'asi'] },
402399
]
403400

@@ -414,8 +411,8 @@ <h1><a href="https://github.com/dy/subscript" class="logo-link" target="_blank"
414411
literal: 'true/false/null', collection: '[1,2], {a:1}', template: '`${}`',
415412
regex: '/re/', unit: '5px', comment: '//',
416413
// Control
417-
block: '{...}', 'if': 'if/else', loop: 'for/while', 'switch': 'switch',
418-
'var': 'let/const', destruct: '{a,b}=', 'try': 'try/catch',
414+
'if': 'if/else', loop: 'for/while', 'switch': 'switch',
415+
'var': 'let/const', 'try': 'try/catch',
419416
// Functions
420417
'function': 'fn(){}', async: 'async/await', 'class': 'class X {}',
421418
accessor: 'get/set', module: 'import/export', asi: 'auto semicolons'
@@ -449,12 +446,10 @@ <h1><a href="https://github.com/dy/subscript" class="logo-link" target="_blank"
449446
regex: 'Regular expressions<br><code>/pattern/</code> <code>/\\d+/g</code>',
450447
unit: 'Unit suffixes<br><code>5px</code> <code>10rem</code> <code>2s</code>',
451448
comment: 'Comments (ignored)<br><code>// line</code> <code>/* block */</code>',
452-
block: 'Statement block<br><code>if (x) { a; b }</code>',
453449
'if': 'Conditionals<br><code>if (c) x</code> <code>if (c) x else y</code>',
454450
loop: 'Loops<br><code>while (c) body</code> <code>for (;;) body</code> <code>for (x of arr)</code>',
455451
'switch': 'Switch statement<br><code>switch (x) { case 1: ... }</code>',
456452
'var': 'Variable declaration<br><code>let x = 1</code> <code>const y = 2</code>',
457-
destruct: 'Destructuring<br><code>const {a, b} = obj</code> <code>const [x, y] = arr</code>',
458453
'try': 'Try/catch/finally<br><code>try { ... } catch (e) { ... }</code>',
459454
'function': 'Function declaration<br><code>function f(a, b) { }</code>',
460455
async: 'Async/await<br><code>async function f() { await x }</code>',
@@ -670,7 +665,7 @@ <h1><a href="https://github.com/dy/subscript" class="logo-link" target="_blank"
670665
// Jessie: practical JS subset with statements
671666
jessie: ['number', 'string', 'assign', 'logical', 'bit', 'cmp', 'equality', 'arithmetic', 'increment', 'seq', 'group', 'access',
672667
'comment', 'identity', 'nullish', 'pow', 'unary', 'literal', 'ternary', 'arrow', 'spread', 'optional',
673-
'collection', 'template', 'regex', 'block', 'var', 'function', 'destruct', 'if', 'loop', 'try', 'switch', 'asi'],
668+
'collection', 'template', 'regex', 'var', 'function', 'if', 'loop', 'try', 'switch', 'asi'],
674669
// Full: all features
675670
full: FEATURES.flatMap(c => c.items),
676671
}
@@ -683,9 +678,8 @@ <h1><a href="https://github.com/dy/subscript" class="logo-link" target="_blank"
683678
let currentWorker = null
684679

685680
// Fetch all feature sources upfront (using mapped paths)
686-
// Include control.js which is imported by function/loop/switch/try
687681
const featureSources = {}
688-
const uniquePaths = [...new Set([...Object.values(FEATURE_PATHS), 'feature/control.js'])]
682+
const uniquePaths = [...new Set(Object.values(FEATURE_PATHS))]
689683
await Promise.all(uniquePaths.map(async path => {
690684
const res = await fetch('./' + path)
691685
if (res.ok) featureSources[path] = await res.text()
@@ -757,26 +751,25 @@ <h1><a href="https://github.com/dy/subscript" class="logo-link" target="_blank"
757751

758752
// Features that export things used by other features
759753
const exports = {
760-
control: ['BREAK', 'CONTINUE', 'RETURN'],
761-
block: ['keyword', 'infix', 'block', 'body'],
754+
'if': ['block', 'body'], // block/body parsing helpers
755+
loop: ['BREAK', 'CONTINUE'], // control flow symbols
756+
arrow: ['RETURN'], // return symbol
757+
'var': ['destructure'], // destructuring
762758
access: ['unsafe', 'isLval', 'prop'],
763-
destruct: ['destructure'],
764759
accessor: ['ACC'],
765760
unit: ['unit']
766761
}
767762

768763
// Feature dependencies - these features import from other features
769-
// Includes transitive dependencies (e.g., group→loop→block means group needs block)
770764
const dependencies = {
771-
// control exports BREAK, CONTINUE, RETURN - used by loop, function, try, switch, group
772-
control: ['loop', 'function', 'try', 'switch', 'group'],
773-
// block exports keyword, infix, block, body - used by control flow features
774-
// Also needed transitively by: group (via loop)
775-
block: ['if', 'loop', 'switch', 'function', 'try', 'var', 'async', 'class', 'module', 'group'],
776-
// loop exports loop - used by features that handle control flow
765+
// if exports block, body - used by control flow features
766+
'if': ['loop', 'switch', 'function', 'try', 'group'],
767+
// loop exports BREAK, CONTINUE - used by try, switch
777768
loop: ['group', 'function', 'try', 'switch'],
778-
// destruct exports destructure - used by var and loop
779-
destruct: ['var', 'loop', 'group'], // group needs loop which needs destruct
769+
// arrow exports RETURN - used by function, loop, try
770+
arrow: ['function', 'loop', 'try'],
771+
// var exports destructure - used by loop
772+
'var': ['loop', 'group'],
780773
// access exports prop, unsafe, isLval - used by group
781774
access: ['group'],
782775
// accessor exports ACC - used by collection
@@ -1160,7 +1153,7 @@ <h1><a href="https://github.com/dy/subscript" class="logo-link" target="_blank"
11601153
// Render features
11611154
let programmaticChange = false
11621155
const featuresEl = document.getElementById('features')
1163-
const DEPS = { 'if': ['block'], loop: ['block'], 'switch': ['block'], 'function': ['block'], 'try': ['block'], destruct: ['var'] } // Hidden dependencies
1156+
const DEPS = {} // Hidden dependencies
11641157

11651158
// Tooltip element for features
11661159
const featTip = document.createElement('div')
@@ -1245,17 +1238,11 @@ <h1><a href="https://github.com/dy/subscript" class="logo-link" target="_blank"
12451238
// Feature dependencies - these features import from other features
12461239
// Includes transitive dependencies (e.g., group→loop→block means group needs block)
12471240
const DEPENDENCIES = {
1248-
// control exports BREAK, CONTINUE, RETURN - used by loop, function, try, switch, group
1249-
control: ['loop', 'function', 'try', 'switch', 'group'],
1250-
// block exports keyword, infix, block, body - used by control flow features
1251-
// Also needed transitively by: group (via loop)
1252-
block: ['if', 'loop', 'switch', 'function', 'try', 'var', 'async', 'class', 'module', 'group'],
1253-
// loop - no longer exports anything needed by other features
1254-
// destruct exports destructure - used by var and loop
1255-
destruct: ['var', 'loop', 'group'], // group needs loop which needs destruct
1256-
// access exports prop, unsafe, isLval - used by group
1241+
'if': ['loop', 'switch', 'function', 'try', 'group'],
1242+
loop: ['group', 'function', 'try', 'switch'],
1243+
arrow: ['function', 'loop', 'try'],
1244+
'var': ['loop', 'group'],
12571245
access: ['group'],
1258-
// accessor exports ACC - used by collection
12591246
accessor: ['collection']
12601247
}
12611248

test/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ export default subscript;
334334
// Literals
335335
'literal', 'collection', 'template', 'regex', 'unit', 'comment',
336336
// Control
337-
'block', 'if', 'loop', 'switch', 'var', 'destruct', 'try',
337+
'if', 'loop', 'switch', 'var', 'try',
338338
// Functions
339339
'function', 'async', 'class', 'accessor', 'module', 'asi'
340340
]

0 commit comments

Comments
 (0)