@danielx/civet 0.4.37 → 0.5.0
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 +65 -61
- package/dist/browser.js +573 -249
- package/dist/main.js +573 -249
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -54,12 +54,12 @@ createCompilerHost := (options: CompilerOptions, moduleSearchLocations : string[
|
|
|
54
54
|
Things Kept from CoffeeScript
|
|
55
55
|
---
|
|
56
56
|
|
|
57
|
-
- `is`
|
|
58
|
-
- `or`, `or=`
|
|
59
|
-
- `and`, `and=`
|
|
60
|
-
- `loop`
|
|
61
|
-
- `unless exp`
|
|
62
|
-
- `until condition`
|
|
57
|
+
- `is` → `===`
|
|
58
|
+
- `or`, `or=` → `||`, `||=`
|
|
59
|
+
- `and`, `and=` → `&&`, `&&=`
|
|
60
|
+
- `loop` → `while(true)`
|
|
61
|
+
- `unless exp` → `if(!exp)`
|
|
62
|
+
- `until condition` → `while(!condition)`
|
|
63
63
|
- Object literal syntax
|
|
64
64
|
```coffee
|
|
65
65
|
x =
|
|
@@ -71,30 +71,30 @@ Things Kept from CoffeeScript
|
|
|
71
71
|
```
|
|
72
72
|
- Optional semi-colons
|
|
73
73
|
- Indentation based block syntax
|
|
74
|
-
- OptionalChain shorthand for index and function application `a?[b]`
|
|
74
|
+
- OptionalChain shorthand for index and function application: `a?[b]` → `a?.[b]`, `a?(b)` → `a?.(b)`
|
|
75
75
|
- `?=` null-coalescing assignment shorthand
|
|
76
|
-
- `@` `this` shorthand `@`
|
|
77
|
-
- Prototype shorthand `X::`
|
|
76
|
+
- `@` `this` shorthand: `@` → `this`, `@id` → `this.id`, `{@id} → {id: this.id}`
|
|
77
|
+
- Prototype shorthand: `X::` → `X.prototype`, `X::a` → `X.prototype.a`
|
|
78
78
|
- Class static shorthand `@`
|
|
79
|
-
- Chained comparisons `a < b < c`
|
|
79
|
+
- Chained comparisons: `a < b < c` → `a < b && b < c`
|
|
80
80
|
- Postfix `if/unless/while/until/for`
|
|
81
81
|
- Block Strings `"""` / `'''`
|
|
82
82
|
- `#{exp}` interpolation in `"""` strings
|
|
83
83
|
- `when` inside `switch` automatically breaks
|
|
84
84
|
- Multiple `,` separated `case`/`when` expressions
|
|
85
|
-
- `else`
|
|
85
|
+
- `else` → `default` in `switch`
|
|
86
86
|
- Range literals `[0...10]`, `[a..b]`, `[x - 2 .. x + 2]`
|
|
87
|
-
- Array slices `list[0...2]`
|
|
88
|
-
- Slice assignment `numbers[3..6] = [-3, -4, -5, -6]`
|
|
87
|
+
- Array slices `list[0...2]` → `list.slice(0, 2)`
|
|
88
|
+
- Slice assignment `numbers[3..6] = [-3, -4, -5, -6]` → `numbers.splice(3, 4, ...[-3, -4, -5, -6])`
|
|
89
89
|
- Implicit returns
|
|
90
|
-
- Late assignment `x + y = z`
|
|
90
|
+
- Late assignment `x + y = z` → `x + (y = z)`
|
|
91
91
|
- Braceless inline objects `x = coolStory: true`
|
|
92
|
-
- Simplified number method calls `1.toFixed()`
|
|
92
|
+
- Simplified number method calls `1.toFixed()` → `1..toFixed()`
|
|
93
93
|
- `if`/`switch`/`for`/`loop`/`while`/`throw` expressions
|
|
94
|
-
- Destructuring object assignment doesn't require being wrapped in parens at the statement level `{a, b} = c`
|
|
94
|
+
- Destructuring object assignment doesn't require being wrapped in parens at the statement level `{a, b} = c` → `({a, b} = c)`
|
|
95
95
|
- Prefix or postfix rest/splats `[...a]`, `x = [a...]`
|
|
96
|
-
- RestProperty in any position `{a, ...b, c} = d`
|
|
97
|
-
- RestElement/RestParameter in any position `(first, ...midle, last) ->`
|
|
96
|
+
- RestProperty in any position `{a, ...b, c} = d` → `{a, c, ...b} = d`
|
|
97
|
+
- RestElement/RestParameter in any position `(first, ...midle, last) ->` → `function(first, ...middle) { let [last] = middle.splice(-1)}`
|
|
98
98
|
- `///` Heregexp
|
|
99
99
|
- With some [changes](#things-changed-from-coffeescript).
|
|
100
100
|
- JSX
|
|
@@ -106,7 +106,7 @@ Most of these can be enabled by adding a [`"civet coffeeCompat"` directive prolo
|
|
|
106
106
|
The goal is to provide a very high level of compatibility with existing CoffeeScript code while offering a fine grained migration path to modern
|
|
107
107
|
Civet.
|
|
108
108
|
|
|
109
|
-
- Implicit `var` declarations (use `civet coffeeCompat` or `"civet autoVar"`)
|
|
109
|
+
- Implicit `var` declarations (use `"civet coffeeCompat"` or `"civet autoVar"`)
|
|
110
110
|
- `on/yes/off/no` (use `true/false`, `"civet coffeeCompat"`, or `"civet coffeeBooleans"` to add them back)
|
|
111
111
|
- `isnt` (use `!==`, `"civet coffeeCompat"`, or `"civet coffeeIsnt"`)
|
|
112
112
|
- `not` (use `!`, `"civet coffeeCompat"`, or `"civet coffeeNot"`)
|
|
@@ -117,32 +117,32 @@ Civet.
|
|
|
117
117
|
- `for from` (use JS `for of`, `"civet coffeeCompat"`, or `"civet coffeeForLoops"`)
|
|
118
118
|
- `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"`)
|
|
119
119
|
- `for ... when <condition>` (use `continue if exp` inside loop, `"civet coffeeCompat"`, or `"civet coffeeForLoops"`)
|
|
120
|
-
- `a ? b` (use `a ?? b`, though it doesn't check for undeclared variables
|
|
121
|
-
- `a of b` (use `a in b`
|
|
120
|
+
- `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)
|
|
121
|
+
- `a of b` (use `a in b` as in JS, or `"civet coffeeCompat"`, or `"civet coffeeOf"`)
|
|
122
122
|
- Backtick embedded JS (replaced by template literals)
|
|
123
123
|
- Will add later
|
|
124
|
-
- `a %% b`
|
|
125
|
-
- Conditional assignment `a?[x] = 3`
|
|
124
|
+
- `a %% b` → `(a % b + b) % b`
|
|
125
|
+
- Conditional assignment `a?[x] = 3` → `a ? a[x] = 3 : undefined`
|
|
126
126
|
- Multiple slice assignment `otherNumbers[0...] = numbers[3..6] = [-3, -4, -5, -6]`
|
|
127
127
|
|
|
128
128
|
Things Changed from CoffeeScript
|
|
129
129
|
---
|
|
130
130
|
|
|
131
|
-
- `==`
|
|
132
|
-
- `!=`
|
|
133
|
-
- `for in` and `for of` are no longer swapped and become their JS equivalents
|
|
134
|
-
- `a in b`
|
|
131
|
+
- `==` → `==` rather than `===` (unless you specify `"civet coffeeCompat"` or `"civet coffeeEq"`)
|
|
132
|
+
- `!=` → `!=` rather than `!==` (unless you specify `"civet coffeeCompat"` or `"civet coffeeEq"`)
|
|
133
|
+
- `for in` and `for of` are no longer swapped and become their JS equivalents (unless you specify `"civet coffeeCompat"` or `"civet CoffeeOf"`)
|
|
134
|
+
- `a in b` now remains `a in b` rather than becoming `b.indexOf(a) >= 0` (unless you specify `"civet coffeeCompat"` or `"coffeeOf"`)
|
|
135
135
|
- `x?.y` now compiles to `x?.y` rather than the `if typeof x !== 'undefined' && x !== null` if check
|
|
136
|
-
- Existential `x?`
|
|
137
|
-
- `x?()`
|
|
136
|
+
- Existential `x?` → `(x != null)` no longer checks for undeclared variables.
|
|
137
|
+
- `x?()` → `x?.()` instead of `if (typeof x === 'function') { x() }`
|
|
138
138
|
- Backtick embedded JS has been replaced with JS template literals.
|
|
139
139
|
- No longer allowing multiple postfix `if/unless` on the same line (use `&&` or `and` to combine conditions).
|
|
140
140
|
- `#{}` interpolation in `""` strings only when `"civet coffeeCompat"` or `"civet coffeeInterpolation"`
|
|
141
|
-
- Expanded chained comparisons to work on more operators `a in b instanceof C`
|
|
142
|
-
- Postfix iteration/conditionals always wrap the statement [#5431](https://github.com/jashkenas/coffeescript/issues/5431)
|
|
143
|
-
`try x() if y`
|
|
141
|
+
- Expanded chained comparisons to work on more operators `a in b instanceof C` → `a in b && b instanceof C`
|
|
142
|
+
- Postfix iteration/conditionals always wrap the statement [#5431](https://github.com/jashkenas/coffeescript/issues/5431):
|
|
143
|
+
`try x() if y` → `if (y) try x()`
|
|
144
144
|
- Civet tries to keep the transpiled output verbatim as much as possible.
|
|
145
|
-
In Coffee `(x)`
|
|
145
|
+
In Coffee `(x)` → `x;` but in Civet `(x)` → `(x)`. Spacing and comments are also preserved as much as possible.
|
|
146
146
|
- Heregex / re.X
|
|
147
147
|
- Stay closer to the [Python spec](https://docs.python.org/3/library/re.html#re.X)
|
|
148
148
|
- Allows both kinds of substitutions `#{..}`, `${..}`.
|
|
@@ -158,7 +158,7 @@ Things Added that CoffeeScript didn't
|
|
|
158
158
|
---
|
|
159
159
|
|
|
160
160
|
- TypeScript Compatibility
|
|
161
|
-
- Auto-rewrite `.[mc]ts`
|
|
161
|
+
- Auto-rewrite `.[mc]ts` → `.[mc]js` in imports (workaround for: https://github.com/microsoft/TypeScript/issues/37582)
|
|
162
162
|
- Function annotations
|
|
163
163
|
- `namespace`
|
|
164
164
|
- `interface`
|
|
@@ -174,46 +174,50 @@ Things Added that CoffeeScript didn't
|
|
|
174
174
|
readonly x = 3
|
|
175
175
|
}
|
|
176
176
|
```
|
|
177
|
-
- JS
|
|
177
|
+
- JS Compatibility
|
|
178
178
|
- `var`, `let`, `const`
|
|
179
179
|
- JS Comment Syntax `//` and `/* */`
|
|
180
180
|
- `function` keyword
|
|
181
|
-
- Braced Blocks
|
|
181
|
+
- Braced Blocks (as an alternative to indentation)
|
|
182
182
|
- `f?.(x)` function application and `a?.[x]` index OptionalChain longhand
|
|
183
183
|
- `a ? b : c` ConditionalExpression
|
|
184
184
|
- `case` statement
|
|
185
185
|
- `do`, `do { ... } until condition`
|
|
186
|
+
- Method definitions `foo(args) ...` in objects/classes
|
|
186
187
|
- `get`/`set` method definitions
|
|
187
188
|
- Private identifiers `#id`
|
|
188
189
|
- Convenience for ES6+ Features
|
|
189
|
-
- Const assignment shorthand `a := b`
|
|
190
|
-
- `@#id`
|
|
191
|
-
- `import` shorthand: `x from ./x`
|
|
192
|
-
- `export` shorthand: `export x, y`
|
|
190
|
+
- Const assignment shorthand: `a := b` → `const a = b`, `{a, b} := c` → `const {a, b} = c`
|
|
191
|
+
- `@#id` → `this.#id` shorthand for private identifiers
|
|
192
|
+
- `import` shorthand: `x from ./x` → `import x from "./x"`
|
|
193
|
+
- `export` shorthand: `export x, y` → `export {x, y}`
|
|
193
194
|
- Triple backtick Template Strings remove leading indentation for clarity
|
|
194
195
|
- Class constructor shorthand `@( ... )`
|
|
195
196
|
- ClassStaticBlock `@ { ... }`
|
|
196
197
|
- `<` as `extends` shorthand
|
|
197
198
|
- 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)
|
|
198
|
-
-
|
|
199
|
-
-
|
|
200
|
-
-
|
|
201
|
-
-
|
|
202
|
-
-
|
|
203
|
-
- Flagging shorthand [from LiveScript](https://livescript.net/#literals) `{+debug, -live}`
|
|
204
|
-
- JSX enhancements:
|
|
199
|
+
- Access: `x.map &.name` → `x.map(a => a.name)`
|
|
200
|
+
- Nested access + slices: `x.map &.profile?.name[0...3]` → `x.map(a => a.profile?.name.slice(0, 3))`
|
|
201
|
+
- Function call: `x.map &.callback a, b` → `x.map($ => $.callback(a, b))`
|
|
202
|
+
- Unary operators: `x.map !!&` → `x.map($ => !!$)`
|
|
203
|
+
- Binary operators: `x.map &+1` → `x.map($ => $+1)`
|
|
204
|
+
- Flagging shorthand [from LiveScript](https://livescript.net/#literals) `{+debug, -live}` → `{debug: true, live: false}`
|
|
205
|
+
- JSX enhancements (inspired by [solid-dsl discussions](https://github.com/solidjs-community/solid-dsl/discussions)):
|
|
205
206
|
- Indentation: instead of explicitly closing `<tag>`s or `<>`s,
|
|
206
207
|
you can indent the children and Civet will close your tags for you
|
|
207
|
-
- Any braced object literal can be used as an attribute
|
|
208
|
-
`{foo}`
|
|
208
|
+
- Any braced object literal can be used as an attribute:
|
|
209
|
+
`{foo}` → `foo={foo}`, `{foo: bar}` → `foo={bar}`,
|
|
209
210
|
`{...foo}` remains as is; methods and getters/setters work too.
|
|
210
|
-
-
|
|
211
|
-
|
|
212
|
-
expressions
|
|
211
|
+
- Attribute values without whitespace or suitably wrapped
|
|
212
|
+
(parenthesized expressions, strings and template strings,
|
|
213
|
+
regular expressions, array literals, braced object literals)
|
|
214
|
+
do not need braces:
|
|
215
|
+
`foo=bar` → `foo={bar}`, `count=count()` → `count={count()}`,
|
|
216
|
+
`sum=x+1` → `sum={x+1}`, `list=[1, 2, 3]` → `list={[1, 2, 3]}`
|
|
213
217
|
- Attributes can use computed property names:
|
|
214
|
-
`[expr]={value}`
|
|
218
|
+
`[expr]={value}` → `{...{[expr]: value}}`
|
|
215
219
|
- CoffeeScript improvements
|
|
216
|
-
- Postfix loop `run() loop`
|
|
220
|
+
- Postfix loop `run() loop` → `while(true) run()`
|
|
217
221
|
- Character range literals `["a".."z"]`, `['f'..'a']`, `['0'..'9']`
|
|
218
222
|
- Shebang line is kept unmodified in output
|
|
219
223
|
```civet
|
|
@@ -229,14 +233,14 @@ Things Changed from ES6
|
|
|
229
233
|
The reasoning is `x -> ...` => `x(function() ...)` in CoffeeScript and having `->` and `=>`
|
|
230
234
|
behave more differently than they already do is bad. Passing an anonymous function to an
|
|
231
235
|
application without parens is also convenient.
|
|
232
|
-
- `for(i of x) ...` defaults to const declaration
|
|
236
|
+
- `for(i of x) ...` defaults to const declaration → `for(const i of x) ...`
|
|
233
237
|
- Disallow comma operator in conditionals and many other places. `if x, y` is not allowed.
|
|
234
238
|
- Comma operator in `case`/`when` instead becomes multiple conditions.
|
|
235
239
|
- Numbers can't end with a dot (otherwise would be ambiguous with CoffeeScript slices `y[0..x]`). This also implies that you can't access properties
|
|
236
240
|
of numbers with `1..toString()` use `1.toString()` instead. When exponent follows a dot it is treated as a property access since an exponent
|
|
237
|
-
could be a valid property `1.e10`
|
|
241
|
+
could be a valid property `1.e10` → `1..e10`. The workaround is to add a trailing zero `1.0e10` or remove the dot before the exponent `1e10`.
|
|
238
242
|
- Additional reserved words `and`, `or`, `loop`, `until`, `unless`
|
|
239
|
-
- Experimental decorator syntax is `@@` instead of `@` because `@` is premium real estate and `@id`
|
|
243
|
+
- Experimental decorator syntax is `@@` instead of `@` because `@` is premium real estate and `@id` → `this.id`, and `@` is also static fields/methods, etc.
|
|
240
244
|
```
|
|
241
245
|
@@classDecorator
|
|
242
246
|
class X
|
|
@@ -259,12 +263,12 @@ Civet provides a compatibility prologue directive that aims to be 97+% compatibl
|
|
|
259
263
|
| coffeeBooleans | `yes`, `no`, `on`, `off` |
|
|
260
264
|
| coffeeComment | `# single line comments` |
|
|
261
265
|
| coffeeDo | `do ->`, disables ES6 do/while |
|
|
262
|
-
| coffeeEq | `==`
|
|
266
|
+
| coffeeEq | `==` → `===`, `!=` → `!==` |
|
|
263
267
|
| coffeeForLoops | for in, of, from loops behave like they do in CoffeeScript |
|
|
264
268
|
| coffeeInterpolation | `"a string with #{myVar}"` |
|
|
265
|
-
| coffeeIsnt | `isnt`
|
|
266
|
-
| coffeeNot | `not`
|
|
267
|
-
| coffeeOf | `a of b`
|
|
269
|
+
| coffeeIsnt | `isnt` → `!==` |
|
|
270
|
+
| coffeeNot | `not` → `!`, `a not instanceof b` → `!(a instanceof b)`, `a not of b` → `!(a in b)` |
|
|
271
|
+
| coffeeOf | `a of b` → `a in b`, `a in b` → `b.indexOf(a) >= 0`, `a not in b` → `b.indexOf(a) < 0` |
|
|
268
272
|
|
|
269
273
|
You can use these with `"civet coffeeCompat"` to opt in to all or use them bit by bit with `"civet coffeeComment coffeeEq coffeeInterpolation"`.
|
|
270
274
|
Another possibility is to slowly remove them to provide a way to migrate files a little at a time `"civet coffeeCompat -coffeeBooleans -coffeeComment -coffeeEq"`.
|