┌───────────────┐
│ Expression │
│ root: true │
│ globalIdx: 1 │
└───────┬───────┘
parentSeq │ ▲
│ │ expr
┌──────────────┐ ┌───────┴─┴─────┐
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
┌───────────────┐ | |
│ Expression │ | |
│ root: true │ | |
│ globalIdx: 1 │ | |
└───────┬───────┘ | |
parentSeq │ ▲ | |
│ │ expr | |
┌──────────────┐ ┌───────┴─┴─────┐ | |
│ State │ │ State │ | |
│ type: cont │ │ type: success │ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Builder { | |
*ensure(...tokens) { | |
for (const token of tokens) { | |
yield* token.type === 'Thunk' ? token.ensure(this) : this.advance(token); | |
} | |
} | |
*allow(...tokens) { | |
for (const token of tokens) { | |
yield* token.type === 'Thunk' ? token.allow(this) : this.advance(token, true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sum(arr) { | |
let acc = 0; | |
for (let i = 0; i < arr.length; i++) { | |
acc += arr[i].val; | |
} | |
return acc; | |
} | |
const array1 = []; | |
const array2 = []; |
Node packages usually ship with scripts that are useful to developers. Common scripts might be build
, test
, or lint
, but you will need to look inside the package.json
file to see what scripts are actually available for a particular package. Here is what a common package with a build
script might look like:
{
"name": "my-package",
"version": "0.1.0",
"scripts": {
"build": "transpile -f lib/index.ts -o /lib/index.js"
},
"devDependencies": {
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function* range(end) { | |
for (let i = 0; i < end; i++) { | |
yield i; | |
} | |
} | |
const a = Array.from(range(65536)); | |
module.exports['for await..of values from one chunk'] = { | |
fn: async function(deferred) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class Coroutine { | |
constructor(generator) { | |
this.generator = generator[Symbol.iterator](); | |
this.current = this.generator?.next(); | |
} | |
get value() { | |
return this.current.value; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.time('new Set'); | |
for (let i = 0; i < 1_000_000; i++) { | |
new Set(); | |
} | |
console.timeEnd('new Set'); | |
console.time('new Map'); | |
for (let i = 0; i < 1_000_000; i++) { | |
new Map(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Grammar } from '@cst-tokens/grammar'; | |
import { objectEntries } from '@cst-tokens/helpers/iterable'; | |
import { eat, match } from '@cst-tokens/helpers/commands'; | |
import { capture, ref, PN } from '@cst-tokens/helpers/shorthand'; | |
// 2-+2+-2 | |
/* | |
$capture = '2'; | |
$node = { type: 'Digit', value: $caputure }; | |
$capture = '-'; |