@danielx/civet 0.4.16 → 0.4.18
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 +27 -34
- package/dist/browser.js +1790 -632
- package/dist/esm.mjs +1 -1
- package/dist/main.js +1790 -632
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -47,25 +47,6 @@ createCompilerHost := (options: CompilerOptions, moduleSearchLocations : string[
|
|
|
47
47
|
fileCache[fileName]
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
ESBuild Plugin
|
|
51
|
-
---
|
|
52
|
-
|
|
53
|
-
```coffee
|
|
54
|
-
esbuild = require "esbuild"
|
|
55
|
-
civetPlugin = require "@danielx/civet/esbuild-plugin"
|
|
56
|
-
|
|
57
|
-
esbuild.build
|
|
58
|
-
entryPoints: ['source/main.civet']
|
|
59
|
-
bundle: true
|
|
60
|
-
platform: 'node'
|
|
61
|
-
outfile: 'dist/main.js'
|
|
62
|
-
plugins: [
|
|
63
|
-
civetPlugin
|
|
64
|
-
]
|
|
65
|
-
.catch -> process.exit 1
|
|
66
|
-
|
|
67
|
-
```
|
|
68
|
-
|
|
69
50
|
Things Kept from CoffeeScript
|
|
70
51
|
---
|
|
71
52
|
|
|
@@ -73,7 +54,7 @@ Things Kept from CoffeeScript
|
|
|
73
54
|
- `or` -> `||`
|
|
74
55
|
- `and` -> `&&`
|
|
75
56
|
- `loop` -> `while(true)`
|
|
76
|
-
- `unless`
|
|
57
|
+
- `unless exp` -> `if(!exp)`
|
|
77
58
|
- `until condition` -> `while(!condition)`
|
|
78
59
|
- Object literal syntax
|
|
79
60
|
```coffee
|
|
@@ -99,31 +80,39 @@ Things Kept from CoffeeScript
|
|
|
99
80
|
- Multiple `,` separated `case`/`when` expressions
|
|
100
81
|
- `else` -> `default` in `switch`
|
|
101
82
|
- Array slices `list[0...2]` -> `list.slice(0, 2)`
|
|
102
|
-
- Slice assignment `numbers[3..6] = [-3, -4, -5, -6]`
|
|
83
|
+
- Slice assignment `numbers[3..6] = [-3, -4, -5, -6]` -> `numbers.splice(3, 4, ...[-3, -4, -5, -6])`
|
|
103
84
|
- Implicit returns
|
|
104
85
|
- Simplified number method calls `1.toFixed()` -> `1..toFixed()`
|
|
86
|
+
- `if`/`switch` expressions
|
|
87
|
+
- Destructuring object assignment doesn't require being wrapped in parens at the statement level `{a, b} = c` -> `({a, b} = c)`
|
|
105
88
|
- JSX 😿
|
|
106
89
|
|
|
107
90
|
Things Removed from CoffeeScript
|
|
108
91
|
---
|
|
109
92
|
|
|
110
|
-
- `
|
|
111
|
-
- `
|
|
112
|
-
- `
|
|
93
|
+
- Implicit `var` declarations (use `civet coffeeCompat` or `"civet autoVar"`)
|
|
94
|
+
- `on/yes/off/no` (use `true/false`, `"civet coffeeCompat"`, or `"civet coffeeBooleans"` to add them back)
|
|
95
|
+
- `isnt` (use `!==`, `"civet coffeeCompat"`, or `"civet coffeeIsnt"`)
|
|
96
|
+
- `not` (use `!`, `"civet coffeeCompat"`, or `"civet coffeeNot"`)
|
|
97
|
+
- `not instanceof` (use `!(a instanceof b)`)
|
|
98
|
+
- `not in`
|
|
99
|
+
- `not of`
|
|
100
|
+
- NOTE: CoffeeScript `not` precedence is dubious. `not a < b` should be equivalent to `!(a < b)` but it is in fact `!a < b`
|
|
113
101
|
- `do` keyword (replaced with JS `do`, invoke using existing `(-> ...)()` syntax)
|
|
114
|
-
- `for from` (use JS `for of`)
|
|
102
|
+
- `for from` (use JS `for of`, `"civet coffeeCompat"`, or `"civet coffeeForLoops"`)
|
|
103
|
+
- `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
|
+
- `for ... when <condition>` (use `continue if exp` inside loop, `"civet coffeeCompat"`, or `"civet coffeeForLoops"`)
|
|
115
105
|
- `and=`, `or=` (don't mix and match words and symbols)
|
|
116
106
|
- `a ? b` (use `a ?? b`, though it doesn't check for undeclared variables)
|
|
107
|
+
- `a of b` (use `a in b` matching JS, or `"civet coffeeCompat"`, or `"civet coffeeOf"`)
|
|
117
108
|
- Iteration expression results
|
|
118
109
|
- Backtick embedded JS (replaced by template literals)
|
|
119
110
|
- Will likely add later
|
|
120
111
|
- Optional assignment `x?.y = 3` -> `x != null ? x.y = 3 : undefined`
|
|
121
|
-
-
|
|
122
|
-
- `
|
|
123
|
-
- Implicit `var` declarations (in compat mode only)
|
|
112
|
+
- Loop expressions (at least in compatibility mode)
|
|
113
|
+
- Conditional assignment `a?[x] = 3` -> `a ? a[x] = 3 : undefined`
|
|
124
114
|
- Might add later
|
|
125
115
|
- Braceless inline objects `x = coolStory: true`
|
|
126
|
-
- Comprensions
|
|
127
116
|
- `///` Heregexp
|
|
128
117
|
- Ranges `[0...10]`
|
|
129
118
|
- Rest parameter in any assignment position
|
|
@@ -136,12 +125,12 @@ Things Changed from CoffeeScript
|
|
|
136
125
|
- `!=` -> `!=` rather than `!==` (can be kept with `"civet coffeeCompat"`)
|
|
137
126
|
- `for in` and `for of` are no longer swapped and become their JS equivalents.
|
|
138
127
|
- `a...` is now `...a` just like JS
|
|
128
|
+
- `a in b` is now `a in b` rather than `b.indexOf(a) >= 0`
|
|
139
129
|
- `x?.y` now compiles to `x?.y` rather than the `if typeof x !== 'undefined' && x !== null` if check
|
|
140
130
|
- Existential `x?` -> `(x != null)` no longer checks for undeclared variables.
|
|
141
131
|
- `x?()` -> `x?.()` instead of `if (typeof x === 'function') { x() }`
|
|
142
132
|
- Backtick embedded JS has been replaced with JS template literals.
|
|
143
133
|
- No longer allowing multiple postfix `if/unless` on the same line (use `&&` or `and` to combine conditions).
|
|
144
|
-
- No `else` block on `unless` (negate condition and use `if`)
|
|
145
134
|
- `#{}` interpolation in `""` strings only when `"civet coffeeCompat"` or `"civet coffeeInterpolation"`
|
|
146
135
|
- Expanded chained comparisons to work on more operators `a in b instanceof C` -> `a in b && b instanceof C`
|
|
147
136
|
- Postfix iteration/conditionals always wrap the statement [#5431](https://github.com/jashkenas/coffeescript/issues/5431)
|
|
@@ -192,12 +181,14 @@ Things Added that CoffeeScript didn't
|
|
|
192
181
|
- Private identifiers `#id`
|
|
193
182
|
- Convenience for ES6+ Features
|
|
194
183
|
- Const assignment shorthand `a := b` -> `const a = b`; `{a, b} := c` -> `const {a, b} = c`
|
|
195
|
-
- `<` as `extends` shorthand
|
|
196
184
|
- `@#id` -> `this.#id` shorthand for private identifiers
|
|
197
185
|
- `import` shorthand `x from ./x` -> `import x from "./x"`
|
|
198
|
-
-
|
|
186
|
+
- Triple backtick Template Strings remove leading indentation for clarity
|
|
199
187
|
- Class constructor shorthand `@( ... )`
|
|
200
188
|
- ClassStaticBlock `@ { ... }`
|
|
189
|
+
- `<` as `extends` shorthand
|
|
190
|
+
- 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)
|
|
191
|
+
`x.map &.name` -> `x.map(a => a.name)`, `x.map &.profile?.name[0...3]` -> `x.map(a => a.profile?.name[0...3])`
|
|
201
192
|
- Postfix loop `run() loop` -> `while(true) run()`
|
|
202
193
|
- Shebang line is kept unmodified in output
|
|
203
194
|
```civet
|
|
@@ -214,12 +205,13 @@ Things Changed from ES6
|
|
|
214
205
|
behave more differently than they already do is bad. Passing an anonymous function to an
|
|
215
206
|
application without parens is also convenient.
|
|
216
207
|
- `for(i of x) ...` defaults to const declaration -> `for(const i of x) ...`
|
|
217
|
-
- Disallow comma operator in conditionals. `if x, y`
|
|
218
|
-
- Comma operator in case
|
|
208
|
+
- Disallow comma operator in conditionals and many other places. `if x, y` is not allowed.
|
|
209
|
+
- Comma operator in `case`/`when` instead becomes multiple conditions.
|
|
219
210
|
- 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
|
|
220
211
|
of numbers with `1..toString()` use `1.toString()` instead. When exponent follows a dot it is treated as a property access since an exponent
|
|
221
212
|
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`.
|
|
222
213
|
- Additional reserved words `and`, `or`, `loop`, `until`, `unless`
|
|
214
|
+
- No whitespace between unary operators and operands. Mandatory whitespace between condition and ternary `?` ex. `x ? a : b` since `x?` is the unary existential operator.
|
|
223
215
|
|
|
224
216
|
CoffeeScript Compatibility
|
|
225
217
|
---
|
|
@@ -231,6 +223,7 @@ coffeeBooleans (yes/no/on/off)
|
|
|
231
223
|
coffeeComment (# single line comments)
|
|
232
224
|
coffeeEq (`==` -> `===`, `!=` -> `!==`)
|
|
233
225
|
coffeeInterpolation (`"a string with {myVar}"`)
|
|
226
|
+
coffeeIsnt (`isnt` -> `!==`)
|
|
234
227
|
```
|
|
235
228
|
|
|
236
229
|
You can use these with `"civet coffeeCompat"` to opt in to all or use them bit by bit with `"civet coffeeComment coffeeEq coffeeInterpolation"`.
|