@danielx/civet 0.4.19-pre.1 → 0.4.19-pre.10
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 +22 -12
- package/dist/browser.js +7059 -2261
- package/dist/civet +8 -2
- package/dist/esm.mjs +1 -1
- package/dist/main.js +7059 -2261
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -69,7 +69,7 @@ Things Kept from CoffeeScript
|
|
|
69
69
|
- Indentation based block syntax
|
|
70
70
|
- OptionalChain shorthand for index and function application `a?[b]` -> `a?.[b]`, `a?(b)` -> `a?.(b)`
|
|
71
71
|
- `?=` null-coalescing assignment shorthand
|
|
72
|
-
- `@` `this` shorthand `@` -> `this`, `@id` -> `this.id`
|
|
72
|
+
- `@` `this` shorthand `@` -> `this`, `@id` -> `this.id`, `{@id} -> {id: this.id}`
|
|
73
73
|
- Prototype shorthand `X::` -> `X.prototype`, `X::a` -> `X.prototype.a`
|
|
74
74
|
- Class static shorthand `@`
|
|
75
75
|
- Chained comparisons `a < b < c` -> `a < b && b < c`
|
|
@@ -79,50 +79,53 @@ Things Kept from CoffeeScript
|
|
|
79
79
|
- `when` inside `switch` automatically breaks
|
|
80
80
|
- Multiple `,` separated `case`/`when` expressions
|
|
81
81
|
- `else` -> `default` in `switch`
|
|
82
|
+
- Range literals `[0...10]`, `[a..b]`, `[x - 2 .. x + 2]`
|
|
82
83
|
- Array slices `list[0...2]` -> `list.slice(0, 2)`
|
|
83
84
|
- Slice assignment `numbers[3..6] = [-3, -4, -5, -6]` -> `numbers.splice(3, 4, ...[-3, -4, -5, -6])`
|
|
84
85
|
- Implicit returns
|
|
86
|
+
- Late assignment `x + y = z` -> `x + (y = z)`
|
|
87
|
+
- Braceless inline objects `x = coolStory: true`
|
|
85
88
|
- Simplified number method calls `1.toFixed()` -> `1..toFixed()`
|
|
86
|
-
- `if`/`switch` expressions
|
|
89
|
+
- `if`/`switch`/`for`/`loop`/`while`/`throw` expressions
|
|
87
90
|
- Destructuring object assignment doesn't require being wrapped in parens at the statement level `{a, b} = c` -> `({a, b} = c)`
|
|
88
91
|
- JSX 😿
|
|
89
92
|
|
|
90
93
|
Things Removed from CoffeeScript
|
|
91
94
|
---
|
|
92
95
|
|
|
96
|
+
Most of these can be enabled by adding a [`"civet coffeeCompat"` directive prologue](#coffeescript-compatibility) to the top of your file.
|
|
97
|
+
The goal is to provide a very high level of compatibility with existing CoffeeScript code while offering a fine grained migration path to modern
|
|
98
|
+
Civet.
|
|
99
|
+
|
|
93
100
|
- Implicit `var` declarations (use `civet coffeeCompat` or `"civet autoVar"`)
|
|
94
101
|
- `on/yes/off/no` (use `true/false`, `"civet coffeeCompat"`, or `"civet coffeeBooleans"` to add them back)
|
|
95
102
|
- `isnt` (use `!==`, `"civet coffeeCompat"`, or `"civet coffeeIsnt"`)
|
|
96
103
|
- `not` (use `!`, `"civet coffeeCompat"`, or `"civet coffeeNot"`)
|
|
97
104
|
- `not instanceof` (use `!(a instanceof b)`)
|
|
98
|
-
- `not in`
|
|
99
105
|
- `not of`
|
|
100
106
|
- NOTE: CoffeeScript `not` precedence is dubious. `not a < b` should be equivalent to `!(a < b)` but it is in fact `!a < b`
|
|
101
|
-
- `do` keyword (replaced with JS `do`, invoke using existing `(-> ...)()` syntax)
|
|
107
|
+
- `do` keyword (replaced with JS `do`, invoke using existing `(-> ...)()` syntax, `"civet coffeeCompat"`, or `"civet coffeeDo"`)
|
|
102
108
|
- `for from` (use JS `for of`, `"civet coffeeCompat"`, or `"civet coffeeForLoops"`)
|
|
103
109
|
- `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"`)
|
|
104
110
|
- `for ... when <condition>` (use `continue if exp` inside loop, `"civet coffeeCompat"`, or `"civet coffeeForLoops"`)
|
|
105
111
|
- `and=`, `or=` (don't mix and match words and symbols)
|
|
106
|
-
- `a ? b` (use `a ?? b`, though it doesn't check for undeclared variables)
|
|
112
|
+
- `a ? b` (use `a ?? b`, though it doesn't check for undeclared variables, `"civet coffeeCompat"`, or `"civet coffeeBinaryExistential"` enables this at the cost of losing JS ternary operator)
|
|
107
113
|
- `a of b` (use `a in b` matching JS, or `"civet coffeeCompat"`, or `"civet coffeeOf"`)
|
|
108
114
|
- Iteration expression results
|
|
109
115
|
- Backtick embedded JS (replaced by template literals)
|
|
110
116
|
- Will likely add later
|
|
111
117
|
- Optional assignment `x?.y = 3` -> `x != null ? x.y = 3 : undefined`
|
|
112
|
-
- Loop expressions (at least in compatibility mode)
|
|
113
118
|
- Conditional assignment `a?[x] = 3` -> `a ? a[x] = 3 : undefined`
|
|
114
119
|
- Might add later
|
|
115
|
-
- Braceless inline objects `x = coolStory: true`
|
|
116
120
|
- `///` Heregexp
|
|
117
|
-
- Ranges `[0...10]`
|
|
118
121
|
- Rest parameter in any assignment position
|
|
119
122
|
- Multiple slice assignment `otherNumbers[0...] = numbers[3..6] = [-3, -4, -5, -6]`
|
|
120
123
|
|
|
121
124
|
Things Changed from CoffeeScript
|
|
122
125
|
---
|
|
123
126
|
|
|
124
|
-
- `==` -> `==` rather than `===` (can be kept with `"civet coffeeCompat"`)
|
|
125
|
-
- `!=` -> `!=` rather than `!==` (can be kept with `"civet coffeeCompat"`)
|
|
127
|
+
- `==` -> `==` rather than `===` (can be kept with `"civet coffeeCompat"` or `"civet coffeeEq"`)
|
|
128
|
+
- `!=` -> `!=` rather than `!==` (can be kept with `"civet coffeeCompat"` or `"civet coffeeEq"`)
|
|
126
129
|
- `for in` and `for of` are no longer swapped and become their JS equivalents.
|
|
127
130
|
- `a...` is now `...a` just like JS
|
|
128
131
|
- `a in b` is now `a in b` rather than `b.indexOf(a) >= 0`
|
|
@@ -193,7 +196,9 @@ Things Added that CoffeeScript didn't
|
|
|
193
196
|
- function call `x.map &.callback a, b` -> `x.map($ => $.callback(a, b))`
|
|
194
197
|
- unary operators `x.map !!&`, -> `x.map($ => !!$)`
|
|
195
198
|
- binary operators `x.map &+1` -> `x.map($ => $+1)`
|
|
196
|
-
-
|
|
199
|
+
- CoffeeScript improvements
|
|
200
|
+
- Postfix loop `run() loop` -> `while(true) run()`
|
|
201
|
+
- Character range literals `["a".."z"]`, `['f'..'a']`, `['0'..'9']`
|
|
197
202
|
- Shebang line is kept unmodified in output
|
|
198
203
|
```civet
|
|
199
204
|
#!./node_modules/.bin/ts-node
|
|
@@ -224,11 +229,16 @@ CoffeeScript Compatibility
|
|
|
224
229
|
Civet provides a compatability prologue directive that aims to be 97+% compatible with existing CoffeeScript2 code (still a work in progress).
|
|
225
230
|
|
|
226
231
|
```
|
|
232
|
+
autoVar (declare implicit vars based on assignment to undeclared identifiers)
|
|
227
233
|
coffeeBooleans (yes/no/on/off)
|
|
228
234
|
coffeeComment (# single line comments)
|
|
235
|
+
coffeeDo ( `do ->`, disables ES6 do/while)
|
|
229
236
|
coffeeEq (`==` -> `===`, `!=` -> `!==`)
|
|
230
|
-
|
|
237
|
+
coffeeForLoops (for in, of, from loops behave like they do in CoffeeScript)
|
|
238
|
+
coffeeInterpolation (`"a string with #{myVar}"`)
|
|
231
239
|
coffeeIsnt (`isnt` -> `!==`)
|
|
240
|
+
coffeeNot (`not` -> "!") (currently doesn't support `not instanceof`, `not of`)
|
|
241
|
+
coffeeOf (`a of b` -> `a in b`, `a in b` -> `b.indexOf(a) >= 0`, `a not in b` -> `b.indexOf(a) < 0`)
|
|
232
242
|
```
|
|
233
243
|
|
|
234
244
|
You can use these with `"civet coffeeCompat"` to opt in to all or use them bit by bit with `"civet coffeeComment coffeeEq coffeeInterpolation"`.
|