@danielx/civet 0.5.33 → 0.5.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -64,170 +64,13 @@ createCompilerHost := (options: CompilerOptions, moduleSearchLocations : string[
64
64
  fileCache[fileName]
65
65
  ```
66
66
 
67
- Things Kept from CoffeeScript
67
+ Overview
68
68
  ---
69
69
 
70
- - `is` `===`
71
- - `or`, `or=` → `||`, `||=`
72
- - `and`, `and=` → `&&`, `&&=`
73
- - `a %% b` → `(a % b + b) % b`
74
- - `loop` → `while(true)`
75
- - `unless exp` → `if(!exp)`
76
- - `until condition` → `while(!condition)`
77
- - Object literal syntax
78
- ```coffee
79
- x =
80
- a: 1
81
- b: 2
82
- c:
83
- x: "pretty"
84
- y: "cool"
85
- ```
86
- - Optional semi-colons
87
- - Indentation based block syntax
88
- - OptionalChain shorthand for index and function application: `a?[b]` → `a?.[b]`, `a?(b)` → `a?.(b)`
89
- - `?=` null-coalescing assignment shorthand
90
- - `@` `this` shorthand: `@` → `this`, `@id` → `this.id`, `{@id} → {id: this.id}`
91
- - Prototype shorthand: `X::` → `X.prototype`, `X::a` → `X.prototype.a`
92
- - Class static shorthand `@`
93
- - Chained comparisons: `a < b < c` → `a < b && b < c`
94
- - Postfix `if/unless/while/until/for`
95
- - Block Strings `"""` / `'''`
96
- - `#{exp}` interpolation in `"""` strings
97
- - `when` inside `switch` automatically breaks
98
- - Multiple `,` separated `case`/`when` expressions
99
- - `else` → `default` in `switch`
100
- - Range literals `[0...10]`, `[a..b]`, `[x - 2 .. x + 2]`
101
- - Array slices `list[0...2]` → `list.slice(0, 2)`
102
- - Slice assignment `numbers[3..6] = [-3, -4, -5, -6]` → `numbers.splice(3, 4, ...[-3, -4, -5, -6])`
103
- - Implicit returns
104
- - Late assignment `x + y = z` → `x + (y = z)`
105
- - Braceless inline objects `x = coolStory: true`
106
- - Simplified number method calls `1.toFixed()` → `1..toFixed()`
107
- - `if`/`switch`/`for`/`loop`/`while`/`throw` expressions
108
- - Destructuring object assignment doesn't require being wrapped in parens at the statement level `{a, b} = c` → `({a, b} = c)`
109
- - Prefix or postfix rest/splats `[...a]`, `x = [a...]`
110
- - RestProperty in any position `{a, ...b, c} = d` → `{a, c, ...b} = d`
111
- - RestElement/RestParameter in any position `(first, ...midle, last) ->` → `function(first, ...middle) { let [last] = middle.splice(-1)}`
112
- - `///` Heregexp
113
- - With some [changes](#things-changed-from-coffeescript).
114
- - JSX
115
-
116
- Things Removed from CoffeeScript
117
- ---
70
+ Civet is essentially a tasteful superset of TypeScript.
118
71
 
119
- Most of these can be enabled by adding a [`"civet coffeeCompat"` directive prologue](#coffeescript-compatibility) to the top of your file.
120
- The goal is to provide a very high level of compatibility with existing CoffeeScript code while offering a fine grained migration path to modern
121
- Civet.
122
-
123
- - Implicit `var` declarations (use `"civet coffeeCompat"` or `"civet autoVar"`)
124
- - `on/yes/off/no` (use `true/false`, `"civet coffeeCompat"`, or `"civet coffeeBooleans"` to add them back)
125
- - `not` (use `!`, `"civet coffeeCompat"`, or `"civet coffeeNot"`)
126
- - `not instanceof` (use `!(a instanceof b)`, `"civet coffeeCompat"`, or `"civet coffeeNot"`)
127
- - `not of` use (`"civet coffeeCompat"`, or `"civet coffeeNot"`)
128
- - NOTE: CoffeeScript `not` precedence is dubious. `not a < b` should be equivalent to `!(a < b)` but it is in fact `!a < b`
129
- - `do` keyword (replaced with JS `do`, invoke using existing `(-> ...)()` syntax, `"civet coffeeCompat"`, or `"civet coffeeDo"`)
130
- - `for from` (use JS `for of`, `"civet coffeeCompat"`, or `"civet coffeeForLoops"`)
131
- - `for own of` (use JS `for in` and check manually, switch to `Map#keys/values/entries`, or use `Object.create(null)`, or `"civet coffeeCompat"`, or `"civet coffeeForLoops"`)
132
- - `for ... when <condition>` (use `continue if exp` inside loop, `"civet coffeeCompat"`, or `"civet coffeeForLoops"`)
133
- - `a ? b` (use `a ?? b`, though it doesn't check for undeclared variables; `"civet coffeeCompat"`, or `"civet coffeeBinaryExistential"` enables `a ? b` at the cost of losing JS ternary operator)
134
- - `a of b` (use `a in b` as in JS, or `"civet coffeeCompat"`, or `"civet coffeeOf"`)
135
- - Backtick embedded JS (replaced by template literals)
136
- - Will add later
137
- - Conditional assignment `a?[x] = 3` → `a ? a[x] = 3 : undefined`
138
- - Multiple slice assignment `otherNumbers[0...] = numbers[3..6] = [-3, -4, -5, -6]`
139
-
140
- Things Changed from CoffeeScript
141
- ---
142
-
143
- - `==` → `==` rather than `===` (unless you specify `"civet coffeeCompat"` or `"civet coffeeEq"`)
144
- - `!=` → `!=` rather than `!==` (unless you specify `"civet coffeeCompat"` or `"civet coffeeEq"`)
145
- - `is not` → `!==`
146
- (unless you specify `"civet coffeeCompat"` or `"civet coffeeNot"`),
147
- instead of `isnt`
148
- (unless you specify `"civet coffeeCompat"` or `"civet coffeeIsnt"`)
149
- - `for in` and `for of` are no longer swapped and become their JS equivalents (unless you specify `"civet coffeeCompat"` or `"civet CoffeeOf"`)
150
- - `a is in b` → `b.indexOf(a) >= 0` and
151
- `a is not in b` → `b.indexOf(a) < 0` instead of `a in b` and `a not in b`;
152
- `a in b` remains `a in b` as in JS, and `a not in b` → `!(a in b)`
153
- (unless you specify `"civet coffeeCompat"` or `"civet coffeeOf"`)
154
- - `x?.y` now compiles to `x?.y` rather than the `if typeof x !== 'undefined' && x !== null` if check
155
- - Existential `x?` → `(x != null)` no longer checks for undeclared variables.
156
- - `x?()` → `x?.()` instead of `if (typeof x === 'function') { x() }`
157
- - Functions don't implicitly return the last value if there's a semicolon
158
- at the end: `-> x` returns `x` but `-> x;` does not
159
- - Backtick embedded JS has been replaced with JS template literals.
160
- - No longer allowing multiple postfix `if/unless` on the same line (use `&&` or `and` to combine conditions).
161
- - `#{}` interpolation in `""` strings only when `"civet coffeeCompat"` or `"civet coffeeInterpolation"`
162
- - Expanded chained comparisons to work on more operators `a in b instanceof C` → `a in b && b instanceof C`
163
- - Postfix iteration/conditionals always wrap the statement [#5431](https://github.com/jashkenas/coffeescript/issues/5431):
164
- `try x() if y` → `if (y) try x()`
165
- - Civet tries to keep the transpiled output verbatim as much as possible.
166
- In Coffee `(x)` → `x;` but in Civet `(x)` → `(x)`. Spacing and comments are also preserved as much as possible.
167
- - Heregex / re.X
168
- - Stay closer to the [Python spec](https://docs.python.org/3/library/re.html#re.X)
169
- - Allows both kinds of substitutions `#{..}`, `${..}`.
170
- - Also allows both kinds of single line comments `//`, `#`.
171
- - Keeps non-newline whitespace inside of character classes.
172
- - Doesn't require escaping `#` after space inside of character classes.
173
- - `#` is always the start of a comment outside of character classes regardless of leading space (CoffeeScript treats
174
- `\s+#` as comment starts inside and outside of character classes).
175
- - Might later add a compat flag to get more CoffeeScript compatibility.
176
- - Might also later add a compat flag to only use ES interpolations and comments inside Heregexes.
177
-
178
- Things Added that CoffeeScript didn't
179
- ---
72
+ ### Implementations of New and Proposed ES Features
180
73
 
181
- - TypeScript Compatibility
182
- - Auto-rewrite `.[mc]ts` → `.[mc]js` in imports (workaround for: https://github.com/microsoft/TypeScript/issues/37582)
183
- - Function annotations
184
- - `namespace`
185
- - `interface`
186
- - TypeParameters
187
- - `!` non-null assertions
188
- - `:=` readonly class field initializer
189
- ```typescript
190
- class A
191
- x := 3
192
- ```
193
- ```typescript
194
- class A {
195
- readonly x = 3
196
- }
197
- ```
198
- - JS Compatibility
199
- - `var`, `let`, `const`
200
- - JS Comment Syntax `//` and `/* */`
201
- - `function` keyword
202
- - Braced Blocks (as an alternative to indentation)
203
- - `f?.(x)` function application and `a?.[x]` index OptionalChain longhand
204
- - `a ? b : c` ConditionalExpression
205
- - `case` statement
206
- - `do`, `do { ... } until condition`
207
- - Method definitions `foo(args) ...` in objects/classes
208
- - `get`/`set` method definitions
209
- - Private identifiers `#id`
210
- - Convenience for ES6+ Features
211
- - Const assignment shorthand: `a := b` → `const a = b`, `{a, b} := c` → `const {a, b} = c`
212
- - Let assignment shorthand (experimental): `a .= b` or `a ::= b` → `let a = b`
213
- - Typed versions of above: `a: number .= 5` → `let a: number = 5`
214
- (but note that `a: number = 5` is the object literal `{a: (number = 5)}`).
215
- - `@#id` → `this.#id` shorthand for private identifiers
216
- - `import` shorthand: `x from ./x` → `import x from "./x"`
217
- - Dynamic `import` shorthand: `import './x'` not at top level
218
- (e.g. `await import './x'` or inside a function) →
219
- `import('./x')`
220
- - `export` shorthand: `export x, y` → `export {x, y}`
221
- - Triple backtick Template Strings remove leading indentation for clarity
222
- - Class constructor shorthand `@( ... )`
223
- - ClassStaticBlock `@ { ... }`
224
- - `<` as `extends` shorthand
225
- - Short function block syntax like [Ruby symbol to proc](https://ruby-doc.org/core-3.1.2/Symbol.html#method-i-to_proc), [Crystal](https://crystal-lang.org/reference/1.6/syntax_and_semantics/blocks_and_procs.html#short-one-parameter-syntax), [Elm record access](https://elm-lang.org/docs/records#access)
226
- - Access: `x.map &.name` → `x.map(a => a.name)`
227
- - Nested access + slices: `x.map &.profile?.name[0...3]` → `x.map(a => a.profile?.name.slice(0, 3))`
228
- - Function call: `x.map &.callback a, b` → `x.map($ => $.callback(a, b))`
229
- - Unary operators: `x.map !!&` → `x.map($ => !!$)`
230
- - Binary operators: `x.map &+1` → `x.map($ => $+1)`
231
74
  - Pipe operator (based on [F# pipes](https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/symbol-and-operator-reference/#function-symbols-and-operators), [Hack pipes](https://docs.hhvm.com/hack/expressions-and-operators/pipe) and the [TC39 proposal](https://github.com/tc39/proposal-pipeline-operator))
232
75
  - `data |> Object.keys |> console.log` equivalent to
233
76
  `console.log(Object.keys(data))`
@@ -235,52 +78,93 @@ Things Added that CoffeeScript didn't
235
78
  to specify how to use left-hand side
236
79
  - `|> await`, `|> yield`, and `|> return` (at end)
237
80
  for wrapping left-hand side with that operation
81
+ - Short function block syntax like [Ruby symbol to proc](https://ruby-doc.org/core-3.1.2/Symbol.html#method-i-to_proc), [Crystal](https://crystal-lang.org/reference/1.6/syntax_and_semantics/blocks_and_procs.html#short-one-parameter-syntax), [Elm record access](https://elm-lang.org/docs/records#access)
82
+ - Access: `x.map &.name` → `x.map(a => a.name)`
83
+ - Nested access + slices: `x.map &.profile?.name[0...3]` → `x.map(a => a.profile?.name.slice(0, 3))`
84
+ - Function call: `x.map &.callback a, b` → `x.map($ => $.callback(a, b))`
85
+ - Unary operators: `x.map !!&` → `x.map($ => !!$)`
86
+ - Binary operators: `x.map &+1` → `x.map($ => $+1)`
238
87
  - Flagging shorthand based on [from LiveScript](https://livescript.net/#literals-objects):
239
88
  `{+debug, -live, !verbose}` → `{debug: true, live: false, verbose: false}`
240
- - JSX enhancements (inspired by [solid-dsl discussions](https://github.com/solidjs-community/solid-dsl/discussions)):
241
- - Indentation: instead of explicitly closing `<tag>`s or `<>`s,
242
- you can indent the children and Civet will close your tags for you
243
- - Multiple adjacent elements and/or fragments get automatically
244
- combined into a fragment.
245
- - Arrow function children do not need to be wrapped in braces
246
- (assuming they are not preceded by text); this is unambiguous because
247
- `>` isn't valid JSX text. For example, `<For> (item) => ...`
248
- (where function body can be indented).
249
- - `#foo` shorthand for `id="foo"`;
250
- also `#"foo bar"`, `` #`foo ${bar}` ``, `#{expr}`
251
- - `.foo` shorthand for `class="foo"` (but must be at least one space after
252
- tag name); also `.foo.bar`, `."foo bar"`, `` .`foo ${bar}` ``, `.{expr}`
253
- - `"civet react"` flag uses `className` instead of `class`
254
- - `+foo` shorthand for `foo={true}`, `-foo`/`!foo` shorthand for `foo={false}`
255
- - Any braced object literal can be used as an attribute:
256
- `{foo}` `foo={foo}`, `{foo: bar}` → `foo={bar}`,
257
- `{...foo}` remains as is; methods and getters/setters work too.
258
- - Attribute `...foo` shorthand for `{...foo}`
259
- - Attribute values without whitespace or suitably wrapped
260
- (parenthesized expressions, strings and template strings,
261
- regular expressions, array literals, braced object literals)
262
- do not need braces:
263
- `foo=bar` `foo={bar}`, `count=count()` → `count={count()}`,
264
- `sum=x+1` → `sum={x+1}`, `list=[1, 2, 3]` → `list={[1, 2, 3]}`
265
- - Attributes can use computed property names:
266
- `[expr]={value}` → `{...{[expr]: value}}`
267
- - `"civet solid"` flag adds correct types for JSX elements and fragments.
268
- Use `"civet solid client"` (default) for client-only code,
269
- `"civet solid server"` for server-only code (SSR only), or
270
- `"civet solid client server"` for isomorphic code that runs on
271
- client and server (SSR + hydration).
272
- - XML comments: `<!-- ... -->` `{/* ... */}`
273
- - CoffeeScript improvements
274
- - Postfix loop `run() loop` → `while(true) run()`
275
- - Character range literals `["a".."z"]`, `['f'..'a']`, `['0'..'9']`
276
- - Shebang line is kept unmodified in output
277
- ```civet
278
- #!./node_modules/.bin/ts-node
279
- console.log "hi"
89
+
90
+
91
+ ### Convenience for ES6+ Features
92
+
93
+ - Const assignment shorthand: `a := b` → `const a = b`, `{a, b} := c` → `const {a, b} = c`
94
+ - Let assignment shorthand: `a .= b` `let a = b`
95
+ - Typed versions of above: `a: number .= 5` `let a: number = 5`
96
+ (but note that `a: number = 5` is the object literal `{a: (number = 5)}`).
97
+ - `@#id` `this.#id` shorthand for private identifiers
98
+ - `import` shorthand: `x from ./x` → `import x from "./x"`
99
+ - Dynamic `import` shorthand: `import './x'` not at top level
100
+ (e.g. `await import './x'` or inside a function)
101
+ `import('./x')`
102
+ - Optional import rename syntax that corresponds to destructuring rename
103
+ `import {x: y} from "./z"` `import {x as y} from "./z"`. You can still
104
+ use `as` to be compatible with existing ES imports.
105
+ - `export` shorthand: `export x, y` → `export {x, y}`
106
+ - Triple backtick Template Strings remove leading indentation for clarity
107
+ - Class constructor shorthand `@( ... )`
108
+ - ClassStaticBlock `@ { ... }`
109
+ - `<` as `extends` shorthand
110
+ - `///` Block RegExp [like Python re.X](https://docs.python.org/3/library/re.html#re.X)
111
+
112
+ ### JSX Enhancements
113
+
114
+ Largely inspired by [solid-dsl discussions](https://github.com/solidjs-community/solid-dsl/discussions)
115
+
116
+ - Indentation: instead of explicitly closing `<tag>`s or `<>`s,
117
+ you can indent the children and Civet will close your tags for you
118
+ - Multiple adjacent elements and/or fragments get automatically
119
+ combined into a fragment.
120
+ - Arrow function children do not need to be wrapped in braces
121
+ (assuming they are not preceded by text); this is unambiguous because
122
+ `>` isn't valid JSX text. For example, `<For> (item) => ...`
123
+ (where function body can be indented).
124
+ - `#foo` shorthand for `id="foo"`;
125
+ also `#"foo bar"`, `` #`foo ${bar}` ``, `#{expr}`
126
+ - `.foo` shorthand for `class="foo"` (but must be at least one space after
127
+ tag name); also `.foo.bar`, `."foo bar"`, `` .`foo ${bar}` ``, `.{expr}`
128
+ - `"civet react"` flag uses `className` instead of `class`
129
+ - `+foo` shorthand for `foo={true}`, `-foo`/`!foo` shorthand for `foo={false}`
130
+ - Any braced object literal can be used as an attribute:
131
+ `{foo}` → `foo={foo}`, `{foo: bar}` → `foo={bar}`,
132
+ `{...foo}` remains as is; methods and getters/setters work too.
133
+ - Attribute `...foo` shorthand for `{...foo}`
134
+ - Attribute values without whitespace or suitably wrapped
135
+ (parenthesized expressions, strings and template strings,
136
+ regular expressions, array literals, braced object literals)
137
+ do not need braces:
138
+ `foo=bar` → `foo={bar}`, `count=count()` → `count={count()}`,
139
+ `sum=x+1` → `sum={x+1}`, `list=[1, 2, 3]` → `list={[1, 2, 3]}`
140
+ - Attributes can use computed property names:
141
+ `[expr]={value}` → `{...{[expr]: value}}`
142
+ - `"civet solid"` flag adds correct types for JSX elements and fragments.
143
+ Use `"civet solid client"` (default) for client-only code,
144
+ `"civet solid server"` for server-only code (SSR only), or
145
+ `"civet solid client server"` for isomorphic code that runs on
146
+ client and server (SSR + hydration).
147
+ - XML comments: `<!-- ... -->` → `{/* ... */}`
148
+
149
+ ### TypeScript Enhancements
150
+
151
+ - Auto-rewrite `.[mc]ts` → `.[mc]js` in imports (workaround for: https://github.com/microsoft/TypeScript/issues/37582)
152
+ - `:=` readonly class field initializer
153
+ ```typescript
154
+ class A
155
+ x := 3
156
+ ```
157
+ ```typescript
158
+ class A {
159
+ readonly x = 3
160
+ }
280
161
  ```
162
+ - Proposal: [Typed Destructuring](https://github.com/DanielXMoore/Civet/discussions/126)
163
+ - Proposal: [Dot Notation for Types](https://github.com/DanielXMoore/Civet/discussions/190)
164
+ - Proposal: [Module Interfaces](https://github.com/DanielXMoore/Civet/discussions/179) https://github.com/microsoft/TypeScript/issues/38511
165
+ - TODO: [Type Declaration Shorthand](https://github.com/DanielXMoore/Civet/issues/176)
281
166
 
282
- Things Changed from ES6
283
- ---
167
+ ### Changes from ES6
284
168
 
285
169
  - Implicit returns, even for multi-statement functions
286
170
  (avoid by specifying a `void` return type, adding a trailing `;` or
@@ -308,38 +192,37 @@ could be a valid property `1.e10` → `1..e10`. The workaround is to add a trail
308
192
  - No whitespace between unary operators and operands. Mandatory whitespace between condition and ternary `?` ex. `x ? a : b` since `x?` is the unary existential operator.
309
193
  - No labels (yet...)
310
194
 
311
- CoffeeScript Compatibility
312
- ---
195
+ ### Scripting Improvements
196
+
197
+ - Shebang line is kept unmodified in output
198
+ ```civet
199
+ #!./node_modules/.bin/ts-node
200
+ console.log "hi"
201
+ ```
313
202
 
314
- Civet provides a compatibility prologue directive that aims to be 97+% compatible with existing CoffeeScript2 code (still a work in progress).
203
+ Comparison to CoffeeScript
204
+ ---
315
205
 
316
- | Configuration | What it enables |
317
- |---------------------|---------------------------------------------------------------------|
318
- | autoVar | declare implicit vars based on assignment to undeclared identifiers |
319
- | coffeeBooleans | `yes`, `no`, `on`, `off` |
320
- | coffeeComment | `# single line comments` |
321
- | coffeeDo | `do ->`, disables ES6 do/while |
322
- | coffeeEq | `==` → `===`, `!=` → `!==` |
323
- | coffeeForLoops | for in, of, from loops behave like they do in CoffeeScript |
324
- | coffeeInterpolation | `"a string with #{myVar}"` |
325
- | coffeeIsnt | `isnt` → `!==` |
326
- | coffeeNot | `not` → `!`, `a not instanceof b` → `!(a instanceof b)`, `a not of b` → `!(a in b)` |
327
- | coffeeOf | `a of b` → `a in b`, `a in b` → `b.indexOf(a) >= 0`, `a not in b` → `b.indexOf(a) < 0` |
328
-
329
- You can use these with `"civet coffeeCompat"` to opt in to all or use them bit by bit with `"civet coffeeComment coffeeEq coffeeInterpolation"`.
330
- Another possibility is to slowly remove them to provide a way to migrate files a little at a time `"civet coffeeCompat -coffeeBooleans -coffeeComment -coffeeEq"`.
331
- Both camel case and hyphens work when specifying options `"civet coffee-compat"`. More options will be added over time until 97+% compatibility is achieved.
206
+ Take a look at this [detailed Civet // CoffeeScript comparision](./notes/Comparison-to-CoffeeScript.md)
332
207
 
333
208
  ECMAScript Compatibility
334
209
  ---
335
210
 
336
- You can also specify `"civet"` prologue directives to increase
211
+ You can specify `"civet"` prologue directives to increase
337
212
  compatibility with ECMAScript/TypeScript:
338
213
 
339
214
  | Configuration | What it enables |
340
215
  |---------------------|---------------------------------------|
341
216
  | -implicit-returns | turn off implicit return of last value in functions |
342
217
 
218
+ Put them at the top of your file:
219
+
220
+ ```
221
+ "civet -implicit-returns"
222
+ ```
223
+
224
+ Your can separate multiple options with spaces.
225
+
343
226
  Other Options
344
227
  ---
345
228
 
package/dist/browser.js CHANGED
@@ -660,6 +660,7 @@ ${input.slice(result.pos)}
660
660
  FromClause,
661
661
  TypeAndImportSpecifier,
662
662
  ImportSpecifier,
663
+ ImportAsToken,
663
664
  ModuleExportName,
664
665
  ModuleSpecifier,
665
666
  UnprocessedModuleSpecifier,
@@ -882,6 +883,9 @@ ${input.slice(result.pos)}
882
883
  TypeBinaryOp,
883
884
  FunctionType,
884
885
  TypeArguments,
886
+ InlineTypeArguments,
887
+ InlineTypeArgument,
888
+ InlineTypeArgumentDelimiter,
885
889
  CompactTypeArguments,
886
890
  TypeArgument,
887
891
  TypeArgumentDelimiter,
@@ -925,6 +929,7 @@ ${input.slice(result.pos)}
925
929
  CoffeeLineContinuationEnabled,
926
930
  CoffeeNotEnabled,
927
931
  CoffeeOfEnabled,
932
+ CoffeePrototypeEnabled,
928
933
  Reset,
929
934
  Init,
930
935
  Indent,
@@ -1349,12 +1354,13 @@ ${input.slice(result.pos)}
1349
1354
  }
1350
1355
  }
1351
1356
  var Arguments$0 = ExplicitArguments;
1352
- var Arguments$1 = $TS($S(ApplicationStart, InsertOpenParen, $Q(_), ArgumentList, InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
1353
- var open = $2;
1354
- var ws = $3;
1355
- var args = $4;
1356
- var close = $5;
1357
- return [open, module.insertTrimmingSpace(ws, ""), args, close];
1357
+ var Arguments$1 = $TS($S($E($S(InlineTypeArguments, $N($S(__, ImplementsToken)))), ApplicationStart, InsertOpenParen, $Q(_), ArgumentList, InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
1358
+ var ta = $1;
1359
+ var open = $3;
1360
+ var ws = $4;
1361
+ var args = $5;
1362
+ var close = $6;
1363
+ return [ta?.[0], open, module.insertTrimmingSpace(ws, ""), args, close];
1358
1364
  });
1359
1365
  function Arguments(state) {
1360
1366
  let eventData;
@@ -3261,9 +3267,9 @@ ${input.slice(result.pos)}
3261
3267
  children
3262
3268
  };
3263
3269
  });
3264
- var PropertyAccess$1 = $TS($S(DoubleColon, $E(IdentifierName)), function($skip, $loc, $0, $1, $2) {
3265
- var p = $1;
3266
- var id = $2;
3270
+ var PropertyAccess$1 = $TS($S(CoffeePrototypeEnabled, DoubleColon, $E(IdentifierName)), function($skip, $loc, $0, $1, $2, $3) {
3271
+ var p = $2;
3272
+ var id = $3;
3267
3273
  if (id) {
3268
3274
  p.token = ".prototype.";
3269
3275
  return [p, id];
@@ -8659,8 +8665,8 @@ ${input.slice(result.pos)}
8659
8665
  return result;
8660
8666
  }
8661
8667
  }
8662
- var NameSpaceImport$0 = $TS($S(Star, __, As, __, ImportedBinding), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
8663
- var binding = $5;
8668
+ var NameSpaceImport$0 = $TS($S(Star, ImportAsToken, __, ImportedBinding), function($skip, $loc, $0, $1, $2, $3, $4) {
8669
+ var binding = $4;
8664
8670
  return {
8665
8671
  type: "Declaration",
8666
8672
  children: $0,
@@ -8770,8 +8776,8 @@ ${input.slice(result.pos)}
8770
8776
  return result;
8771
8777
  }
8772
8778
  }
8773
- var ImportSpecifier$0 = $TS($S(__, ModuleExportName, __, As, __, ImportedBinding, ObjectPropertyDelimiter), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7) {
8774
- var binding = $6;
8779
+ var ImportSpecifier$0 = $TS($S(__, ModuleExportName, ImportAsToken, __, ImportedBinding, ObjectPropertyDelimiter), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
8780
+ var binding = $5;
8775
8781
  return {
8776
8782
  binding,
8777
8783
  children: $0
@@ -8806,6 +8812,44 @@ ${input.slice(result.pos)}
8806
8812
  return result;
8807
8813
  }
8808
8814
  }
8815
+ var ImportAsToken$0 = $S(__, As);
8816
+ var ImportAsToken$1 = $TS($S(Loc, __, Colon, $E($EXPECT($L4, fail, 'ImportAsToken " "'))), function($skip, $loc, $0, $1, $2, $3, $4) {
8817
+ var l = $1;
8818
+ var ws = $2;
8819
+ var c = $3;
8820
+ const children = [
8821
+ ...ws,
8822
+ { ...c, token: "as " }
8823
+ ];
8824
+ if (!ws.length) {
8825
+ children.unshift({ $loc: l.$loc, token: " " });
8826
+ }
8827
+ return {
8828
+ children
8829
+ };
8830
+ });
8831
+ function ImportAsToken(state) {
8832
+ let eventData;
8833
+ if (state.events) {
8834
+ const result = state.events.enter?.("ImportAsToken", state);
8835
+ if (result) {
8836
+ if (result.cache)
8837
+ return result.cache;
8838
+ eventData = result.data;
8839
+ }
8840
+ }
8841
+ if (state.tokenize) {
8842
+ const result = $TOKEN("ImportAsToken", state, ImportAsToken$0(state) || ImportAsToken$1(state));
8843
+ if (state.events)
8844
+ state.events.exit?.("ImportAsToken", state, result, eventData);
8845
+ return result;
8846
+ } else {
8847
+ const result = ImportAsToken$0(state) || ImportAsToken$1(state);
8848
+ if (state.events)
8849
+ state.events.exit?.("ImportAsToken", state, result, eventData);
8850
+ return result;
8851
+ }
8852
+ }
8809
8853
  var ModuleExportName$0 = StringLiteral;
8810
8854
  var ModuleExportName$1 = IdentifierName;
8811
8855
  function ModuleExportName(state) {
@@ -14834,6 +14878,78 @@ ${input.slice(result.pos)}
14834
14878
  return result;
14835
14879
  }
14836
14880
  }
14881
+ var InlineTypeArguments$0 = $TS($S($Q(_), $EXPECT($L120, fail, 'InlineTypeArguments "<"'), $P(InlineTypeArgument), $Q(_), $EXPECT($L25, fail, 'InlineTypeArguments ">"')), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
14882
+ return { ts: true, children: $0 };
14883
+ });
14884
+ function InlineTypeArguments(state) {
14885
+ let eventData;
14886
+ if (state.events) {
14887
+ const result = state.events.enter?.("InlineTypeArguments", state);
14888
+ if (result) {
14889
+ if (result.cache)
14890
+ return result.cache;
14891
+ eventData = result.data;
14892
+ }
14893
+ }
14894
+ if (state.tokenize) {
14895
+ const result = $TOKEN("InlineTypeArguments", state, InlineTypeArguments$0(state));
14896
+ if (state.events)
14897
+ state.events.exit?.("InlineTypeArguments", state, result, eventData);
14898
+ return result;
14899
+ } else {
14900
+ const result = InlineTypeArguments$0(state);
14901
+ if (state.events)
14902
+ state.events.exit?.("InlineTypeArguments", state, result, eventData);
14903
+ return result;
14904
+ }
14905
+ }
14906
+ var InlineTypeArgument$0 = $S($Q(_), Type, InlineTypeArgumentDelimiter);
14907
+ function InlineTypeArgument(state) {
14908
+ let eventData;
14909
+ if (state.events) {
14910
+ const result = state.events.enter?.("InlineTypeArgument", state);
14911
+ if (result) {
14912
+ if (result.cache)
14913
+ return result.cache;
14914
+ eventData = result.data;
14915
+ }
14916
+ }
14917
+ if (state.tokenize) {
14918
+ const result = $TOKEN("InlineTypeArgument", state, InlineTypeArgument$0(state));
14919
+ if (state.events)
14920
+ state.events.exit?.("InlineTypeArgument", state, result, eventData);
14921
+ return result;
14922
+ } else {
14923
+ const result = InlineTypeArgument$0(state);
14924
+ if (state.events)
14925
+ state.events.exit?.("InlineTypeArgument", state, result, eventData);
14926
+ return result;
14927
+ }
14928
+ }
14929
+ var InlineTypeArgumentDelimiter$0 = $S($Q(_), Comma);
14930
+ var InlineTypeArgumentDelimiter$1 = $Y($S($Q(_), $EXPECT($L25, fail, 'InlineTypeArgumentDelimiter ">"')));
14931
+ function InlineTypeArgumentDelimiter(state) {
14932
+ let eventData;
14933
+ if (state.events) {
14934
+ const result = state.events.enter?.("InlineTypeArgumentDelimiter", state);
14935
+ if (result) {
14936
+ if (result.cache)
14937
+ return result.cache;
14938
+ eventData = result.data;
14939
+ }
14940
+ }
14941
+ if (state.tokenize) {
14942
+ const result = $TOKEN("InlineTypeArgumentDelimiter", state, InlineTypeArgumentDelimiter$0(state) || InlineTypeArgumentDelimiter$1(state));
14943
+ if (state.events)
14944
+ state.events.exit?.("InlineTypeArgumentDelimiter", state, result, eventData);
14945
+ return result;
14946
+ } else {
14947
+ const result = InlineTypeArgumentDelimiter$0(state) || InlineTypeArgumentDelimiter$1(state);
14948
+ if (state.events)
14949
+ state.events.exit?.("InlineTypeArgumentDelimiter", state, result, eventData);
14950
+ return result;
14951
+ }
14952
+ }
14837
14953
  var CompactTypeArguments$0 = $TS($S($EXPECT($L120, fail, 'CompactTypeArguments "<"'), $P(TypeArgument), __, $EXPECT($L25, fail, 'CompactTypeArguments ">"')), function($skip, $loc, $0, $1, $2, $3, $4) {
14838
14954
  return { ts: true, children: $0 };
14839
14955
  });
@@ -15943,6 +16059,33 @@ ${input.slice(result.pos)}
15943
16059
  return result;
15944
16060
  }
15945
16061
  }
16062
+ var CoffeePrototypeEnabled$0 = $TV($EXPECT($L0, fail, 'CoffeePrototypeEnabled ""'), function($skip, $loc, $0, $1) {
16063
+ if (module.config.coffeePrototype)
16064
+ return;
16065
+ return $skip;
16066
+ });
16067
+ function CoffeePrototypeEnabled(state) {
16068
+ let eventData;
16069
+ if (state.events) {
16070
+ const result = state.events.enter?.("CoffeePrototypeEnabled", state);
16071
+ if (result) {
16072
+ if (result.cache)
16073
+ return result.cache;
16074
+ eventData = result.data;
16075
+ }
16076
+ }
16077
+ if (state.tokenize) {
16078
+ const result = $TOKEN("CoffeePrototypeEnabled", state, CoffeePrototypeEnabled$0(state));
16079
+ if (state.events)
16080
+ state.events.exit?.("CoffeePrototypeEnabled", state, result, eventData);
16081
+ return result;
16082
+ } else {
16083
+ const result = CoffeePrototypeEnabled$0(state);
16084
+ if (state.events)
16085
+ state.events.exit?.("CoffeePrototypeEnabled", state, result, eventData);
16086
+ return result;
16087
+ }
16088
+ }
15946
16089
  var Reset$0 = $TV($EXPECT($L0, fail, 'Reset ""'), function($skip, $loc, $0, $1) {
15947
16090
  module.indentLevels = [{
15948
16091
  level: 0,
@@ -15973,6 +16116,7 @@ ${input.slice(result.pos)}
15973
16116
  coffeeLineContinuation: false,
15974
16117
  coffeeNot: false,
15975
16118
  coffeeOf: false,
16119
+ coffeePrototype: false,
15976
16120
  implicitReturns: true,
15977
16121
  react: false,
15978
16122
  solid: false,
@@ -16127,6 +16271,7 @@ ${input.slice(result.pos)}
16127
16271
  this.coffeeLineContinuation = true;
16128
16272
  this.coffeeNot = true;
16129
16273
  this.coffeeOf = true;
16274
+ this.coffeePrototype = true;
16130
16275
  } else {
16131
16276
  this.autoVar = false;
16132
16277
  this.coffeeBinaryExistential = false;
@@ -16141,6 +16286,7 @@ ${input.slice(result.pos)}
16141
16286
  this.coffeeLineContinuation = false;
16142
16287
  this.coffeeNot = false;
16143
16288
  this.coffeeOf = false;
16289
+ this.coffeePrototype = false;
16144
16290
  }
16145
16291
  }
16146
16292
  });
@@ -16278,7 +16424,7 @@ ${input.slice(result.pos)}
16278
16424
  id: "results"
16279
16425
  };
16280
16426
  insertPush(exp.block, resultsRef);
16281
- exp.children = ["(", resultsRef, "=>{", ...exp.children, "; return ", resultsRef, "})([])"];
16427
+ exp.children = ["(()=>{const ", resultsRef, "=[];", ...exp.children, "; return ", resultsRef, "})()"];
16282
16428
  }
16283
16429
  function wrapIterationReturningResults(statement, outerRef) {
16284
16430
  const resultsRef = {
@@ -17404,6 +17550,7 @@ ${input.slice(result.pos)}
17404
17550
  compile: () => compile,
17405
17551
  default: () => main_default,
17406
17552
  generate: () => generate_default,
17553
+ isCompileError: () => isCompileError,
17407
17554
  parse: () => parse,
17408
17555
  util: () => util_exports
17409
17556
  });
@@ -17887,6 +18034,11 @@ ${"//#"} sourceMappingURL=data:application/json;base64,${base64Encode2(JSON.stri
17887
18034
  };
17888
18035
  return events;
17889
18036
  };
17890
- var main_default = { parse, generate: generate_default, util: util_exports, compile };
18037
+ var isCompileError = function(err) {
18038
+ return err instanceof Error && [err.message, err.name, err.filename, err.line, err.column, err.offset].every(function(value) {
18039
+ return value !== void 0;
18040
+ });
18041
+ };
18042
+ var main_default = { parse, generate: generate_default, util: util_exports, compile, isCompileError };
17891
18043
  return __toCommonJS(main_exports);
17892
18044
  })();
package/dist/main.js CHANGED
@@ -659,6 +659,7 @@ ${input.slice(result.pos)}
659
659
  FromClause,
660
660
  TypeAndImportSpecifier,
661
661
  ImportSpecifier,
662
+ ImportAsToken,
662
663
  ModuleExportName,
663
664
  ModuleSpecifier,
664
665
  UnprocessedModuleSpecifier,
@@ -881,6 +882,9 @@ ${input.slice(result.pos)}
881
882
  TypeBinaryOp,
882
883
  FunctionType,
883
884
  TypeArguments,
885
+ InlineTypeArguments,
886
+ InlineTypeArgument,
887
+ InlineTypeArgumentDelimiter,
884
888
  CompactTypeArguments,
885
889
  TypeArgument,
886
890
  TypeArgumentDelimiter,
@@ -924,6 +928,7 @@ ${input.slice(result.pos)}
924
928
  CoffeeLineContinuationEnabled,
925
929
  CoffeeNotEnabled,
926
930
  CoffeeOfEnabled,
931
+ CoffeePrototypeEnabled,
927
932
  Reset,
928
933
  Init,
929
934
  Indent,
@@ -1348,12 +1353,13 @@ ${input.slice(result.pos)}
1348
1353
  }
1349
1354
  }
1350
1355
  var Arguments$0 = ExplicitArguments;
1351
- var Arguments$1 = $TS($S(ApplicationStart, InsertOpenParen, $Q(_), ArgumentList, InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
1352
- var open = $2;
1353
- var ws = $3;
1354
- var args = $4;
1355
- var close = $5;
1356
- return [open, module2.insertTrimmingSpace(ws, ""), args, close];
1356
+ var Arguments$1 = $TS($S($E($S(InlineTypeArguments, $N($S(__, ImplementsToken)))), ApplicationStart, InsertOpenParen, $Q(_), ArgumentList, InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
1357
+ var ta = $1;
1358
+ var open = $3;
1359
+ var ws = $4;
1360
+ var args = $5;
1361
+ var close = $6;
1362
+ return [ta?.[0], open, module2.insertTrimmingSpace(ws, ""), args, close];
1357
1363
  });
1358
1364
  function Arguments(state) {
1359
1365
  let eventData;
@@ -3260,9 +3266,9 @@ ${input.slice(result.pos)}
3260
3266
  children
3261
3267
  };
3262
3268
  });
3263
- var PropertyAccess$1 = $TS($S(DoubleColon, $E(IdentifierName)), function($skip, $loc, $0, $1, $2) {
3264
- var p = $1;
3265
- var id = $2;
3269
+ var PropertyAccess$1 = $TS($S(CoffeePrototypeEnabled, DoubleColon, $E(IdentifierName)), function($skip, $loc, $0, $1, $2, $3) {
3270
+ var p = $2;
3271
+ var id = $3;
3266
3272
  if (id) {
3267
3273
  p.token = ".prototype.";
3268
3274
  return [p, id];
@@ -8658,8 +8664,8 @@ ${input.slice(result.pos)}
8658
8664
  return result;
8659
8665
  }
8660
8666
  }
8661
- var NameSpaceImport$0 = $TS($S(Star, __, As, __, ImportedBinding), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
8662
- var binding = $5;
8667
+ var NameSpaceImport$0 = $TS($S(Star, ImportAsToken, __, ImportedBinding), function($skip, $loc, $0, $1, $2, $3, $4) {
8668
+ var binding = $4;
8663
8669
  return {
8664
8670
  type: "Declaration",
8665
8671
  children: $0,
@@ -8769,8 +8775,8 @@ ${input.slice(result.pos)}
8769
8775
  return result;
8770
8776
  }
8771
8777
  }
8772
- var ImportSpecifier$0 = $TS($S(__, ModuleExportName, __, As, __, ImportedBinding, ObjectPropertyDelimiter), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7) {
8773
- var binding = $6;
8778
+ var ImportSpecifier$0 = $TS($S(__, ModuleExportName, ImportAsToken, __, ImportedBinding, ObjectPropertyDelimiter), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
8779
+ var binding = $5;
8774
8780
  return {
8775
8781
  binding,
8776
8782
  children: $0
@@ -8805,6 +8811,44 @@ ${input.slice(result.pos)}
8805
8811
  return result;
8806
8812
  }
8807
8813
  }
8814
+ var ImportAsToken$0 = $S(__, As);
8815
+ var ImportAsToken$1 = $TS($S(Loc, __, Colon, $E($EXPECT($L4, fail, 'ImportAsToken " "'))), function($skip, $loc, $0, $1, $2, $3, $4) {
8816
+ var l = $1;
8817
+ var ws = $2;
8818
+ var c = $3;
8819
+ const children = [
8820
+ ...ws,
8821
+ { ...c, token: "as " }
8822
+ ];
8823
+ if (!ws.length) {
8824
+ children.unshift({ $loc: l.$loc, token: " " });
8825
+ }
8826
+ return {
8827
+ children
8828
+ };
8829
+ });
8830
+ function ImportAsToken(state) {
8831
+ let eventData;
8832
+ if (state.events) {
8833
+ const result = state.events.enter?.("ImportAsToken", state);
8834
+ if (result) {
8835
+ if (result.cache)
8836
+ return result.cache;
8837
+ eventData = result.data;
8838
+ }
8839
+ }
8840
+ if (state.tokenize) {
8841
+ const result = $TOKEN("ImportAsToken", state, ImportAsToken$0(state) || ImportAsToken$1(state));
8842
+ if (state.events)
8843
+ state.events.exit?.("ImportAsToken", state, result, eventData);
8844
+ return result;
8845
+ } else {
8846
+ const result = ImportAsToken$0(state) || ImportAsToken$1(state);
8847
+ if (state.events)
8848
+ state.events.exit?.("ImportAsToken", state, result, eventData);
8849
+ return result;
8850
+ }
8851
+ }
8808
8852
  var ModuleExportName$0 = StringLiteral;
8809
8853
  var ModuleExportName$1 = IdentifierName;
8810
8854
  function ModuleExportName(state) {
@@ -14833,6 +14877,78 @@ ${input.slice(result.pos)}
14833
14877
  return result;
14834
14878
  }
14835
14879
  }
14880
+ var InlineTypeArguments$0 = $TS($S($Q(_), $EXPECT($L120, fail, 'InlineTypeArguments "<"'), $P(InlineTypeArgument), $Q(_), $EXPECT($L25, fail, 'InlineTypeArguments ">"')), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
14881
+ return { ts: true, children: $0 };
14882
+ });
14883
+ function InlineTypeArguments(state) {
14884
+ let eventData;
14885
+ if (state.events) {
14886
+ const result = state.events.enter?.("InlineTypeArguments", state);
14887
+ if (result) {
14888
+ if (result.cache)
14889
+ return result.cache;
14890
+ eventData = result.data;
14891
+ }
14892
+ }
14893
+ if (state.tokenize) {
14894
+ const result = $TOKEN("InlineTypeArguments", state, InlineTypeArguments$0(state));
14895
+ if (state.events)
14896
+ state.events.exit?.("InlineTypeArguments", state, result, eventData);
14897
+ return result;
14898
+ } else {
14899
+ const result = InlineTypeArguments$0(state);
14900
+ if (state.events)
14901
+ state.events.exit?.("InlineTypeArguments", state, result, eventData);
14902
+ return result;
14903
+ }
14904
+ }
14905
+ var InlineTypeArgument$0 = $S($Q(_), Type, InlineTypeArgumentDelimiter);
14906
+ function InlineTypeArgument(state) {
14907
+ let eventData;
14908
+ if (state.events) {
14909
+ const result = state.events.enter?.("InlineTypeArgument", state);
14910
+ if (result) {
14911
+ if (result.cache)
14912
+ return result.cache;
14913
+ eventData = result.data;
14914
+ }
14915
+ }
14916
+ if (state.tokenize) {
14917
+ const result = $TOKEN("InlineTypeArgument", state, InlineTypeArgument$0(state));
14918
+ if (state.events)
14919
+ state.events.exit?.("InlineTypeArgument", state, result, eventData);
14920
+ return result;
14921
+ } else {
14922
+ const result = InlineTypeArgument$0(state);
14923
+ if (state.events)
14924
+ state.events.exit?.("InlineTypeArgument", state, result, eventData);
14925
+ return result;
14926
+ }
14927
+ }
14928
+ var InlineTypeArgumentDelimiter$0 = $S($Q(_), Comma);
14929
+ var InlineTypeArgumentDelimiter$1 = $Y($S($Q(_), $EXPECT($L25, fail, 'InlineTypeArgumentDelimiter ">"')));
14930
+ function InlineTypeArgumentDelimiter(state) {
14931
+ let eventData;
14932
+ if (state.events) {
14933
+ const result = state.events.enter?.("InlineTypeArgumentDelimiter", state);
14934
+ if (result) {
14935
+ if (result.cache)
14936
+ return result.cache;
14937
+ eventData = result.data;
14938
+ }
14939
+ }
14940
+ if (state.tokenize) {
14941
+ const result = $TOKEN("InlineTypeArgumentDelimiter", state, InlineTypeArgumentDelimiter$0(state) || InlineTypeArgumentDelimiter$1(state));
14942
+ if (state.events)
14943
+ state.events.exit?.("InlineTypeArgumentDelimiter", state, result, eventData);
14944
+ return result;
14945
+ } else {
14946
+ const result = InlineTypeArgumentDelimiter$0(state) || InlineTypeArgumentDelimiter$1(state);
14947
+ if (state.events)
14948
+ state.events.exit?.("InlineTypeArgumentDelimiter", state, result, eventData);
14949
+ return result;
14950
+ }
14951
+ }
14836
14952
  var CompactTypeArguments$0 = $TS($S($EXPECT($L120, fail, 'CompactTypeArguments "<"'), $P(TypeArgument), __, $EXPECT($L25, fail, 'CompactTypeArguments ">"')), function($skip, $loc, $0, $1, $2, $3, $4) {
14837
14953
  return { ts: true, children: $0 };
14838
14954
  });
@@ -15942,6 +16058,33 @@ ${input.slice(result.pos)}
15942
16058
  return result;
15943
16059
  }
15944
16060
  }
16061
+ var CoffeePrototypeEnabled$0 = $TV($EXPECT($L0, fail, 'CoffeePrototypeEnabled ""'), function($skip, $loc, $0, $1) {
16062
+ if (module2.config.coffeePrototype)
16063
+ return;
16064
+ return $skip;
16065
+ });
16066
+ function CoffeePrototypeEnabled(state) {
16067
+ let eventData;
16068
+ if (state.events) {
16069
+ const result = state.events.enter?.("CoffeePrototypeEnabled", state);
16070
+ if (result) {
16071
+ if (result.cache)
16072
+ return result.cache;
16073
+ eventData = result.data;
16074
+ }
16075
+ }
16076
+ if (state.tokenize) {
16077
+ const result = $TOKEN("CoffeePrototypeEnabled", state, CoffeePrototypeEnabled$0(state));
16078
+ if (state.events)
16079
+ state.events.exit?.("CoffeePrototypeEnabled", state, result, eventData);
16080
+ return result;
16081
+ } else {
16082
+ const result = CoffeePrototypeEnabled$0(state);
16083
+ if (state.events)
16084
+ state.events.exit?.("CoffeePrototypeEnabled", state, result, eventData);
16085
+ return result;
16086
+ }
16087
+ }
15945
16088
  var Reset$0 = $TV($EXPECT($L0, fail, 'Reset ""'), function($skip, $loc, $0, $1) {
15946
16089
  module2.indentLevels = [{
15947
16090
  level: 0,
@@ -15972,6 +16115,7 @@ ${input.slice(result.pos)}
15972
16115
  coffeeLineContinuation: false,
15973
16116
  coffeeNot: false,
15974
16117
  coffeeOf: false,
16118
+ coffeePrototype: false,
15975
16119
  implicitReturns: true,
15976
16120
  react: false,
15977
16121
  solid: false,
@@ -16126,6 +16270,7 @@ ${input.slice(result.pos)}
16126
16270
  this.coffeeLineContinuation = true;
16127
16271
  this.coffeeNot = true;
16128
16272
  this.coffeeOf = true;
16273
+ this.coffeePrototype = true;
16129
16274
  } else {
16130
16275
  this.autoVar = false;
16131
16276
  this.coffeeBinaryExistential = false;
@@ -16140,6 +16285,7 @@ ${input.slice(result.pos)}
16140
16285
  this.coffeeLineContinuation = false;
16141
16286
  this.coffeeNot = false;
16142
16287
  this.coffeeOf = false;
16288
+ this.coffeePrototype = false;
16143
16289
  }
16144
16290
  }
16145
16291
  });
@@ -16277,7 +16423,7 @@ ${input.slice(result.pos)}
16277
16423
  id: "results"
16278
16424
  };
16279
16425
  insertPush(exp.block, resultsRef);
16280
- exp.children = ["(", resultsRef, "=>{", ...exp.children, "; return ", resultsRef, "})([])"];
16426
+ exp.children = ["(()=>{const ", resultsRef, "=[];", ...exp.children, "; return ", resultsRef, "})()"];
16281
16427
  }
16282
16428
  function wrapIterationReturningResults(statement, outerRef) {
16283
16429
  const resultsRef = {
@@ -17403,6 +17549,7 @@ __export(main_exports, {
17403
17549
  compile: () => compile,
17404
17550
  default: () => main_default,
17405
17551
  generate: () => generate_default,
17552
+ isCompileError: () => isCompileError,
17406
17553
  parse: () => parse,
17407
17554
  util: () => util_exports
17408
17555
  });
@@ -17887,11 +18034,17 @@ makeCache = function() {
17887
18034
  };
17888
18035
  return events;
17889
18036
  };
17890
- var main_default = { parse, generate: generate_default, util: util_exports, compile };
18037
+ var isCompileError = function(err) {
18038
+ return err instanceof Error && [err.message, err.name, err.filename, err.line, err.column, err.offset].every(function(value) {
18039
+ return value !== void 0;
18040
+ });
18041
+ };
18042
+ var main_default = { parse, generate: generate_default, util: util_exports, compile, isCompileError };
17891
18043
  // Annotate the CommonJS export names for ESM import in node:
17892
18044
  0 && (module.exports = {
17893
18045
  compile,
17894
18046
  generate,
18047
+ isCompileError,
17895
18048
  parse,
17896
18049
  util
17897
18050
  });
package/dist/main.mjs CHANGED
@@ -657,6 +657,7 @@ ${input.slice(result.pos)}
657
657
  FromClause,
658
658
  TypeAndImportSpecifier,
659
659
  ImportSpecifier,
660
+ ImportAsToken,
660
661
  ModuleExportName,
661
662
  ModuleSpecifier,
662
663
  UnprocessedModuleSpecifier,
@@ -879,6 +880,9 @@ ${input.slice(result.pos)}
879
880
  TypeBinaryOp,
880
881
  FunctionType,
881
882
  TypeArguments,
883
+ InlineTypeArguments,
884
+ InlineTypeArgument,
885
+ InlineTypeArgumentDelimiter,
882
886
  CompactTypeArguments,
883
887
  TypeArgument,
884
888
  TypeArgumentDelimiter,
@@ -922,6 +926,7 @@ ${input.slice(result.pos)}
922
926
  CoffeeLineContinuationEnabled,
923
927
  CoffeeNotEnabled,
924
928
  CoffeeOfEnabled,
929
+ CoffeePrototypeEnabled,
925
930
  Reset,
926
931
  Init,
927
932
  Indent,
@@ -1346,12 +1351,13 @@ ${input.slice(result.pos)}
1346
1351
  }
1347
1352
  }
1348
1353
  var Arguments$0 = ExplicitArguments;
1349
- var Arguments$1 = $TS($S(ApplicationStart, InsertOpenParen, $Q(_), ArgumentList, InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
1350
- var open = $2;
1351
- var ws = $3;
1352
- var args = $4;
1353
- var close = $5;
1354
- return [open, module.insertTrimmingSpace(ws, ""), args, close];
1354
+ var Arguments$1 = $TS($S($E($S(InlineTypeArguments, $N($S(__, ImplementsToken)))), ApplicationStart, InsertOpenParen, $Q(_), ArgumentList, InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
1355
+ var ta = $1;
1356
+ var open = $3;
1357
+ var ws = $4;
1358
+ var args = $5;
1359
+ var close = $6;
1360
+ return [ta?.[0], open, module.insertTrimmingSpace(ws, ""), args, close];
1355
1361
  });
1356
1362
  function Arguments(state) {
1357
1363
  let eventData;
@@ -3258,9 +3264,9 @@ ${input.slice(result.pos)}
3258
3264
  children
3259
3265
  };
3260
3266
  });
3261
- var PropertyAccess$1 = $TS($S(DoubleColon, $E(IdentifierName)), function($skip, $loc, $0, $1, $2) {
3262
- var p = $1;
3263
- var id = $2;
3267
+ var PropertyAccess$1 = $TS($S(CoffeePrototypeEnabled, DoubleColon, $E(IdentifierName)), function($skip, $loc, $0, $1, $2, $3) {
3268
+ var p = $2;
3269
+ var id = $3;
3264
3270
  if (id) {
3265
3271
  p.token = ".prototype.";
3266
3272
  return [p, id];
@@ -8656,8 +8662,8 @@ ${input.slice(result.pos)}
8656
8662
  return result;
8657
8663
  }
8658
8664
  }
8659
- var NameSpaceImport$0 = $TS($S(Star, __, As, __, ImportedBinding), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
8660
- var binding = $5;
8665
+ var NameSpaceImport$0 = $TS($S(Star, ImportAsToken, __, ImportedBinding), function($skip, $loc, $0, $1, $2, $3, $4) {
8666
+ var binding = $4;
8661
8667
  return {
8662
8668
  type: "Declaration",
8663
8669
  children: $0,
@@ -8767,8 +8773,8 @@ ${input.slice(result.pos)}
8767
8773
  return result;
8768
8774
  }
8769
8775
  }
8770
- var ImportSpecifier$0 = $TS($S(__, ModuleExportName, __, As, __, ImportedBinding, ObjectPropertyDelimiter), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7) {
8771
- var binding = $6;
8776
+ var ImportSpecifier$0 = $TS($S(__, ModuleExportName, ImportAsToken, __, ImportedBinding, ObjectPropertyDelimiter), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
8777
+ var binding = $5;
8772
8778
  return {
8773
8779
  binding,
8774
8780
  children: $0
@@ -8803,6 +8809,44 @@ ${input.slice(result.pos)}
8803
8809
  return result;
8804
8810
  }
8805
8811
  }
8812
+ var ImportAsToken$0 = $S(__, As);
8813
+ var ImportAsToken$1 = $TS($S(Loc, __, Colon, $E($EXPECT($L4, fail, 'ImportAsToken " "'))), function($skip, $loc, $0, $1, $2, $3, $4) {
8814
+ var l = $1;
8815
+ var ws = $2;
8816
+ var c = $3;
8817
+ const children = [
8818
+ ...ws,
8819
+ { ...c, token: "as " }
8820
+ ];
8821
+ if (!ws.length) {
8822
+ children.unshift({ $loc: l.$loc, token: " " });
8823
+ }
8824
+ return {
8825
+ children
8826
+ };
8827
+ });
8828
+ function ImportAsToken(state) {
8829
+ let eventData;
8830
+ if (state.events) {
8831
+ const result = state.events.enter?.("ImportAsToken", state);
8832
+ if (result) {
8833
+ if (result.cache)
8834
+ return result.cache;
8835
+ eventData = result.data;
8836
+ }
8837
+ }
8838
+ if (state.tokenize) {
8839
+ const result = $TOKEN("ImportAsToken", state, ImportAsToken$0(state) || ImportAsToken$1(state));
8840
+ if (state.events)
8841
+ state.events.exit?.("ImportAsToken", state, result, eventData);
8842
+ return result;
8843
+ } else {
8844
+ const result = ImportAsToken$0(state) || ImportAsToken$1(state);
8845
+ if (state.events)
8846
+ state.events.exit?.("ImportAsToken", state, result, eventData);
8847
+ return result;
8848
+ }
8849
+ }
8806
8850
  var ModuleExportName$0 = StringLiteral;
8807
8851
  var ModuleExportName$1 = IdentifierName;
8808
8852
  function ModuleExportName(state) {
@@ -14831,6 +14875,78 @@ ${input.slice(result.pos)}
14831
14875
  return result;
14832
14876
  }
14833
14877
  }
14878
+ var InlineTypeArguments$0 = $TS($S($Q(_), $EXPECT($L120, fail, 'InlineTypeArguments "<"'), $P(InlineTypeArgument), $Q(_), $EXPECT($L25, fail, 'InlineTypeArguments ">"')), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
14879
+ return { ts: true, children: $0 };
14880
+ });
14881
+ function InlineTypeArguments(state) {
14882
+ let eventData;
14883
+ if (state.events) {
14884
+ const result = state.events.enter?.("InlineTypeArguments", state);
14885
+ if (result) {
14886
+ if (result.cache)
14887
+ return result.cache;
14888
+ eventData = result.data;
14889
+ }
14890
+ }
14891
+ if (state.tokenize) {
14892
+ const result = $TOKEN("InlineTypeArguments", state, InlineTypeArguments$0(state));
14893
+ if (state.events)
14894
+ state.events.exit?.("InlineTypeArguments", state, result, eventData);
14895
+ return result;
14896
+ } else {
14897
+ const result = InlineTypeArguments$0(state);
14898
+ if (state.events)
14899
+ state.events.exit?.("InlineTypeArguments", state, result, eventData);
14900
+ return result;
14901
+ }
14902
+ }
14903
+ var InlineTypeArgument$0 = $S($Q(_), Type, InlineTypeArgumentDelimiter);
14904
+ function InlineTypeArgument(state) {
14905
+ let eventData;
14906
+ if (state.events) {
14907
+ const result = state.events.enter?.("InlineTypeArgument", state);
14908
+ if (result) {
14909
+ if (result.cache)
14910
+ return result.cache;
14911
+ eventData = result.data;
14912
+ }
14913
+ }
14914
+ if (state.tokenize) {
14915
+ const result = $TOKEN("InlineTypeArgument", state, InlineTypeArgument$0(state));
14916
+ if (state.events)
14917
+ state.events.exit?.("InlineTypeArgument", state, result, eventData);
14918
+ return result;
14919
+ } else {
14920
+ const result = InlineTypeArgument$0(state);
14921
+ if (state.events)
14922
+ state.events.exit?.("InlineTypeArgument", state, result, eventData);
14923
+ return result;
14924
+ }
14925
+ }
14926
+ var InlineTypeArgumentDelimiter$0 = $S($Q(_), Comma);
14927
+ var InlineTypeArgumentDelimiter$1 = $Y($S($Q(_), $EXPECT($L25, fail, 'InlineTypeArgumentDelimiter ">"')));
14928
+ function InlineTypeArgumentDelimiter(state) {
14929
+ let eventData;
14930
+ if (state.events) {
14931
+ const result = state.events.enter?.("InlineTypeArgumentDelimiter", state);
14932
+ if (result) {
14933
+ if (result.cache)
14934
+ return result.cache;
14935
+ eventData = result.data;
14936
+ }
14937
+ }
14938
+ if (state.tokenize) {
14939
+ const result = $TOKEN("InlineTypeArgumentDelimiter", state, InlineTypeArgumentDelimiter$0(state) || InlineTypeArgumentDelimiter$1(state));
14940
+ if (state.events)
14941
+ state.events.exit?.("InlineTypeArgumentDelimiter", state, result, eventData);
14942
+ return result;
14943
+ } else {
14944
+ const result = InlineTypeArgumentDelimiter$0(state) || InlineTypeArgumentDelimiter$1(state);
14945
+ if (state.events)
14946
+ state.events.exit?.("InlineTypeArgumentDelimiter", state, result, eventData);
14947
+ return result;
14948
+ }
14949
+ }
14834
14950
  var CompactTypeArguments$0 = $TS($S($EXPECT($L120, fail, 'CompactTypeArguments "<"'), $P(TypeArgument), __, $EXPECT($L25, fail, 'CompactTypeArguments ">"')), function($skip, $loc, $0, $1, $2, $3, $4) {
14835
14951
  return { ts: true, children: $0 };
14836
14952
  });
@@ -15940,6 +16056,33 @@ ${input.slice(result.pos)}
15940
16056
  return result;
15941
16057
  }
15942
16058
  }
16059
+ var CoffeePrototypeEnabled$0 = $TV($EXPECT($L0, fail, 'CoffeePrototypeEnabled ""'), function($skip, $loc, $0, $1) {
16060
+ if (module.config.coffeePrototype)
16061
+ return;
16062
+ return $skip;
16063
+ });
16064
+ function CoffeePrototypeEnabled(state) {
16065
+ let eventData;
16066
+ if (state.events) {
16067
+ const result = state.events.enter?.("CoffeePrototypeEnabled", state);
16068
+ if (result) {
16069
+ if (result.cache)
16070
+ return result.cache;
16071
+ eventData = result.data;
16072
+ }
16073
+ }
16074
+ if (state.tokenize) {
16075
+ const result = $TOKEN("CoffeePrototypeEnabled", state, CoffeePrototypeEnabled$0(state));
16076
+ if (state.events)
16077
+ state.events.exit?.("CoffeePrototypeEnabled", state, result, eventData);
16078
+ return result;
16079
+ } else {
16080
+ const result = CoffeePrototypeEnabled$0(state);
16081
+ if (state.events)
16082
+ state.events.exit?.("CoffeePrototypeEnabled", state, result, eventData);
16083
+ return result;
16084
+ }
16085
+ }
15943
16086
  var Reset$0 = $TV($EXPECT($L0, fail, 'Reset ""'), function($skip, $loc, $0, $1) {
15944
16087
  module.indentLevels = [{
15945
16088
  level: 0,
@@ -15970,6 +16113,7 @@ ${input.slice(result.pos)}
15970
16113
  coffeeLineContinuation: false,
15971
16114
  coffeeNot: false,
15972
16115
  coffeeOf: false,
16116
+ coffeePrototype: false,
15973
16117
  implicitReturns: true,
15974
16118
  react: false,
15975
16119
  solid: false,
@@ -16124,6 +16268,7 @@ ${input.slice(result.pos)}
16124
16268
  this.coffeeLineContinuation = true;
16125
16269
  this.coffeeNot = true;
16126
16270
  this.coffeeOf = true;
16271
+ this.coffeePrototype = true;
16127
16272
  } else {
16128
16273
  this.autoVar = false;
16129
16274
  this.coffeeBinaryExistential = false;
@@ -16138,6 +16283,7 @@ ${input.slice(result.pos)}
16138
16283
  this.coffeeLineContinuation = false;
16139
16284
  this.coffeeNot = false;
16140
16285
  this.coffeeOf = false;
16286
+ this.coffeePrototype = false;
16141
16287
  }
16142
16288
  }
16143
16289
  });
@@ -16275,7 +16421,7 @@ ${input.slice(result.pos)}
16275
16421
  id: "results"
16276
16422
  };
16277
16423
  insertPush(exp.block, resultsRef);
16278
- exp.children = ["(", resultsRef, "=>{", ...exp.children, "; return ", resultsRef, "})([])"];
16424
+ exp.children = ["(()=>{const ", resultsRef, "=[];", ...exp.children, "; return ", resultsRef, "})()"];
16279
16425
  }
16280
16426
  function wrapIterationReturningResults(statement, outerRef) {
16281
16427
  const resultsRef = {
@@ -17876,11 +18022,17 @@ makeCache = function() {
17876
18022
  };
17877
18023
  return events;
17878
18024
  };
17879
- var main_default = { parse, generate: generate_default, util: util_exports, compile };
18025
+ var isCompileError = function(err) {
18026
+ return err instanceof Error && [err.message, err.name, err.filename, err.line, err.column, err.offset].every(function(value) {
18027
+ return value !== void 0;
18028
+ });
18029
+ };
18030
+ var main_default = { parse, generate: generate_default, util: util_exports, compile, isCompileError };
17880
18031
  export {
17881
18032
  compile,
17882
18033
  main_default as default,
17883
18034
  generate_default as generate,
18035
+ isCompileError,
17884
18036
  parse,
17885
18037
  util_exports as util
17886
18038
  };
package/dist/types.d.ts CHANGED
@@ -16,6 +16,17 @@ declare module "@danielx/civet" {
16
16
  }
17
17
  }
18
18
 
19
+ // TODO: Import ParseError class from Hera
20
+ export type ParseError = {
21
+ message: string
22
+ name: string
23
+ filename: string
24
+ line: number
25
+ column: number
26
+ offset: number
27
+ }
28
+ export function isCompileError(err: any): err is ParseError
29
+
19
30
  export function compile<T extends CompileOptions>(source: string, options?: T): T extends { sourceMap: true } ? {
20
31
  code: string,
21
32
  sourceMap: SourceMap,
@@ -25,6 +36,7 @@ declare module "@danielx/civet" {
25
36
 
26
37
  const Civet: {
27
38
  compile: typeof compile
39
+ isCompileError: typeof isCompileError
28
40
  parse: typeof parse
29
41
  generate: typeof generate
30
42
  util: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
- "version": "0.5.33",
3
+ "version": "0.5.34",
4
4
  "description": "CoffeeScript style syntax for TypeScript",
5
5
  "main": "dist/main.js",
6
6
  "module": "dist/main.mjs",