@danielx/civet 0.4.19-pre.1 → 0.4.19-pre.2
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 +16 -5
- package/dist/browser.js +54 -7
- package/dist/main.js +54 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -79,6 +79,7 @@ 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
|
|
@@ -90,6 +91,10 @@ Things Kept from CoffeeScript
|
|
|
90
91
|
Things Removed from CoffeeScript
|
|
91
92
|
---
|
|
92
93
|
|
|
94
|
+
Most of these can be enabled by adding a [`"civet coffeeCompat"` directive prologue](#coffeescript-compatibility) to the top of your file.
|
|
95
|
+
The goal is to provide a very high level of compatibility with existing CoffeeScript code while offering a fine grained migration path to modern
|
|
96
|
+
Civet.
|
|
97
|
+
|
|
93
98
|
- Implicit `var` declarations (use `civet coffeeCompat` or `"civet autoVar"`)
|
|
94
99
|
- `on/yes/off/no` (use `true/false`, `"civet coffeeCompat"`, or `"civet coffeeBooleans"` to add them back)
|
|
95
100
|
- `isnt` (use `!==`, `"civet coffeeCompat"`, or `"civet coffeeIsnt"`)
|
|
@@ -98,7 +103,7 @@ Things Removed from CoffeeScript
|
|
|
98
103
|
- `not in`
|
|
99
104
|
- `not of`
|
|
100
105
|
- 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)
|
|
106
|
+
- `do` keyword (replaced with JS `do`, invoke using existing `(-> ...)()` syntax, `"civet coffeeCompat"`, or `"civet coffeeDo"`)
|
|
102
107
|
- `for from` (use JS `for of`, `"civet coffeeCompat"`, or `"civet coffeeForLoops"`)
|
|
103
108
|
- `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
109
|
- `for ... when <condition>` (use `continue if exp` inside loop, `"civet coffeeCompat"`, or `"civet coffeeForLoops"`)
|
|
@@ -114,15 +119,14 @@ Things Removed from CoffeeScript
|
|
|
114
119
|
- Might add later
|
|
115
120
|
- Braceless inline objects `x = coolStory: true`
|
|
116
121
|
- `///` Heregexp
|
|
117
|
-
- Ranges `[0...10]`
|
|
118
122
|
- Rest parameter in any assignment position
|
|
119
123
|
- Multiple slice assignment `otherNumbers[0...] = numbers[3..6] = [-3, -4, -5, -6]`
|
|
120
124
|
|
|
121
125
|
Things Changed from CoffeeScript
|
|
122
126
|
---
|
|
123
127
|
|
|
124
|
-
- `==` -> `==` rather than `===` (can be kept with `"civet coffeeCompat"`)
|
|
125
|
-
- `!=` -> `!=` rather than `!==` (can be kept with `"civet coffeeCompat"`)
|
|
128
|
+
- `==` -> `==` rather than `===` (can be kept with `"civet coffeeCompat"` or `"civet coffeeEq"`)
|
|
129
|
+
- `!=` -> `!=` rather than `!==` (can be kept with `"civet coffeeCompat"` or `"civet coffeeEq"`)
|
|
126
130
|
- `for in` and `for of` are no longer swapped and become their JS equivalents.
|
|
127
131
|
- `a...` is now `...a` just like JS
|
|
128
132
|
- `a in b` is now `a in b` rather than `b.indexOf(a) >= 0`
|
|
@@ -193,7 +197,9 @@ Things Added that CoffeeScript didn't
|
|
|
193
197
|
- function call `x.map &.callback a, b` -> `x.map($ => $.callback(a, b))`
|
|
194
198
|
- unary operators `x.map !!&`, -> `x.map($ => !!$)`
|
|
195
199
|
- binary operators `x.map &+1` -> `x.map($ => $+1)`
|
|
196
|
-
-
|
|
200
|
+
- CoffeeScript improvements
|
|
201
|
+
- Postfix loop `run() loop` -> `while(true) run()`
|
|
202
|
+
- Character range literals `["a".."z"]`, `['f'..'a']`, `['0'..'9']`
|
|
197
203
|
- Shebang line is kept unmodified in output
|
|
198
204
|
```civet
|
|
199
205
|
#!./node_modules/.bin/ts-node
|
|
@@ -224,11 +230,16 @@ CoffeeScript Compatibility
|
|
|
224
230
|
Civet provides a compatability prologue directive that aims to be 97+% compatible with existing CoffeeScript2 code (still a work in progress).
|
|
225
231
|
|
|
226
232
|
```
|
|
233
|
+
autoVar (declare implicit vars based on assignment to undeclared identifiers)
|
|
227
234
|
coffeeBooleans (yes/no/on/off)
|
|
228
235
|
coffeeComment (# single line comments)
|
|
236
|
+
coffeeDo ( `do ->`, disables ES6 do/while)
|
|
229
237
|
coffeeEq (`==` -> `===`, `!=` -> `!==`)
|
|
238
|
+
coffeeForLoops (for in, of, from loops behavie like they do in CoffeeScript 2)
|
|
230
239
|
coffeeInterpolation (`"a string with {myVar}"`)
|
|
231
240
|
coffeeIsnt (`isnt` -> `!==`)
|
|
241
|
+
coffeeNot (`not` -> "!") (currently doesn't support `not instanceof`, `not in`, `not of`)
|
|
242
|
+
coffeeOf (`a of b` -> `a in b`)
|
|
232
243
|
```
|
|
233
244
|
|
|
234
245
|
You can use these with `"civet coffeeCompat"` to opt in to all or use them bit by bit with `"civet coffeeComment coffeeEq coffeeInterpolation"`.
|
package/dist/browser.js
CHANGED
|
@@ -1227,7 +1227,7 @@ var Civet = (() => {
|
|
|
1227
1227
|
return result;
|
|
1228
1228
|
}
|
|
1229
1229
|
});
|
|
1230
|
-
var UnaryExpression$1 = $TS($S(CoffeeDoEnabled, Do, __, ExtendedExpression), function($skip, $loc, $0, $1, $2, $3, $4) {
|
|
1230
|
+
var UnaryExpression$1 = $TS($S(CoffeeDoEnabled, Do, __, $C($S(LeftHandSideExpression, $N($S(__, AssignmentOpSymbol))), ArrowFunction, ExtendedExpression)), function($skip, $loc, $0, $1, $2, $3, $4) {
|
|
1231
1231
|
var ws = $3;
|
|
1232
1232
|
var exp = $4;
|
|
1233
1233
|
module.insertTrimmingSpace(ws, "");
|
|
@@ -2568,12 +2568,59 @@ var Civet = (() => {
|
|
|
2568
2568
|
const inclusive = range.token === "..";
|
|
2569
2569
|
range.token = ",";
|
|
2570
2570
|
if (s.type === "Literal" && e.type === "Literal") {
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2571
|
+
let start, end;
|
|
2572
|
+
if (s.raw[0] === "'") {
|
|
2573
|
+
start = s.raw.match(/^'(.*)'$/)[1];
|
|
2574
|
+
} else {
|
|
2575
|
+
start = JSON.parse(s.raw);
|
|
2576
|
+
}
|
|
2577
|
+
if (e.raw[0] === "'") {
|
|
2578
|
+
end = e.raw.match(/^'(.*)'$/)[1];
|
|
2579
|
+
} else {
|
|
2580
|
+
end = JSON.parse(e.raw);
|
|
2581
|
+
}
|
|
2582
|
+
if (typeof start !== typeof end) {
|
|
2583
|
+
throw new Error("Range start and end must be of the same type");
|
|
2584
|
+
}
|
|
2585
|
+
if (typeof start === "string") {
|
|
2586
|
+
if (start.length !== 1 || end.length !== 1) {
|
|
2587
|
+
throw new Error("String range start and end must be a single character");
|
|
2588
|
+
}
|
|
2589
|
+
const startCode = start.charCodeAt(0);
|
|
2590
|
+
const endCode = end.charCodeAt(0);
|
|
2591
|
+
const step = startCode < endCode ? 1 : -1;
|
|
2592
|
+
const length = Math.abs(endCode - startCode) + (inclusive ? 1 : 0);
|
|
2593
|
+
if (length <= 26) {
|
|
2594
|
+
return {
|
|
2595
|
+
type: "RangeExpression",
|
|
2596
|
+
children: ["[", Array.from({ length }, (_2, i) => JSON.stringify(String.fromCharCode(startCode + i * step))).join(", "), "]"],
|
|
2597
|
+
inclusive,
|
|
2598
|
+
start: s,
|
|
2599
|
+
end: e
|
|
2600
|
+
};
|
|
2601
|
+
} else {
|
|
2602
|
+
const inclusiveAdjust2 = inclusive ? " + 1" : "";
|
|
2603
|
+
const children2 = ["((s, e) => {let step = e > s ? 1 : -1; return Array.from({length: Math.abs(e - s)", inclusiveAdjust2, "}, (_, i) => String.fromCharCode(s + i * step))})(", startCode.toString(), ws, range, endCode.toString(), ")"];
|
|
2604
|
+
return {
|
|
2605
|
+
type: "RangeExpression",
|
|
2606
|
+
children: children2,
|
|
2607
|
+
inclusive,
|
|
2608
|
+
start: s,
|
|
2609
|
+
end: e
|
|
2610
|
+
};
|
|
2611
|
+
}
|
|
2612
|
+
} else if (typeof start === "number") {
|
|
2613
|
+
const step = end > start ? 1 : -1;
|
|
2614
|
+
const length = Math.abs(end - start) + (inclusive ? 1 : 0);
|
|
2615
|
+
if (length <= 20) {
|
|
2616
|
+
return {
|
|
2617
|
+
type: "RangeExpression",
|
|
2618
|
+
children: ["[", Array.from({ length }, (_2, i) => start + i * step).join(", "), "]"],
|
|
2619
|
+
inclusive,
|
|
2620
|
+
start: s,
|
|
2621
|
+
end: e
|
|
2622
|
+
};
|
|
2623
|
+
}
|
|
2577
2624
|
}
|
|
2578
2625
|
}
|
|
2579
2626
|
const inclusiveAdjust = inclusive ? " + 1" : "";
|
package/dist/main.js
CHANGED
|
@@ -1226,7 +1226,7 @@ var require_parser = __commonJS({
|
|
|
1226
1226
|
return result;
|
|
1227
1227
|
}
|
|
1228
1228
|
});
|
|
1229
|
-
var UnaryExpression$1 = $TS($S(CoffeeDoEnabled, Do, __, ExtendedExpression), function($skip, $loc, $0, $1, $2, $3, $4) {
|
|
1229
|
+
var UnaryExpression$1 = $TS($S(CoffeeDoEnabled, Do, __, $C($S(LeftHandSideExpression, $N($S(__, AssignmentOpSymbol))), ArrowFunction, ExtendedExpression)), function($skip, $loc, $0, $1, $2, $3, $4) {
|
|
1230
1230
|
var ws = $3;
|
|
1231
1231
|
var exp = $4;
|
|
1232
1232
|
module2.insertTrimmingSpace(ws, "");
|
|
@@ -2567,12 +2567,59 @@ var require_parser = __commonJS({
|
|
|
2567
2567
|
const inclusive = range.token === "..";
|
|
2568
2568
|
range.token = ",";
|
|
2569
2569
|
if (s.type === "Literal" && e.type === "Literal") {
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2570
|
+
let start, end;
|
|
2571
|
+
if (s.raw[0] === "'") {
|
|
2572
|
+
start = s.raw.match(/^'(.*)'$/)[1];
|
|
2573
|
+
} else {
|
|
2574
|
+
start = JSON.parse(s.raw);
|
|
2575
|
+
}
|
|
2576
|
+
if (e.raw[0] === "'") {
|
|
2577
|
+
end = e.raw.match(/^'(.*)'$/)[1];
|
|
2578
|
+
} else {
|
|
2579
|
+
end = JSON.parse(e.raw);
|
|
2580
|
+
}
|
|
2581
|
+
if (typeof start !== typeof end) {
|
|
2582
|
+
throw new Error("Range start and end must be of the same type");
|
|
2583
|
+
}
|
|
2584
|
+
if (typeof start === "string") {
|
|
2585
|
+
if (start.length !== 1 || end.length !== 1) {
|
|
2586
|
+
throw new Error("String range start and end must be a single character");
|
|
2587
|
+
}
|
|
2588
|
+
const startCode = start.charCodeAt(0);
|
|
2589
|
+
const endCode = end.charCodeAt(0);
|
|
2590
|
+
const step = startCode < endCode ? 1 : -1;
|
|
2591
|
+
const length = Math.abs(endCode - startCode) + (inclusive ? 1 : 0);
|
|
2592
|
+
if (length <= 26) {
|
|
2593
|
+
return {
|
|
2594
|
+
type: "RangeExpression",
|
|
2595
|
+
children: ["[", Array.from({ length }, (_2, i) => JSON.stringify(String.fromCharCode(startCode + i * step))).join(", "), "]"],
|
|
2596
|
+
inclusive,
|
|
2597
|
+
start: s,
|
|
2598
|
+
end: e
|
|
2599
|
+
};
|
|
2600
|
+
} else {
|
|
2601
|
+
const inclusiveAdjust2 = inclusive ? " + 1" : "";
|
|
2602
|
+
const children2 = ["((s, e) => {let step = e > s ? 1 : -1; return Array.from({length: Math.abs(e - s)", inclusiveAdjust2, "}, (_, i) => String.fromCharCode(s + i * step))})(", startCode.toString(), ws, range, endCode.toString(), ")"];
|
|
2603
|
+
return {
|
|
2604
|
+
type: "RangeExpression",
|
|
2605
|
+
children: children2,
|
|
2606
|
+
inclusive,
|
|
2607
|
+
start: s,
|
|
2608
|
+
end: e
|
|
2609
|
+
};
|
|
2610
|
+
}
|
|
2611
|
+
} else if (typeof start === "number") {
|
|
2612
|
+
const step = end > start ? 1 : -1;
|
|
2613
|
+
const length = Math.abs(end - start) + (inclusive ? 1 : 0);
|
|
2614
|
+
if (length <= 20) {
|
|
2615
|
+
return {
|
|
2616
|
+
type: "RangeExpression",
|
|
2617
|
+
children: ["[", Array.from({ length }, (_2, i) => start + i * step).join(", "), "]"],
|
|
2618
|
+
inclusive,
|
|
2619
|
+
start: s,
|
|
2620
|
+
end: e
|
|
2621
|
+
};
|
|
2622
|
+
}
|
|
2576
2623
|
}
|
|
2577
2624
|
}
|
|
2578
2625
|
const inclusiveAdjust = inclusive ? " + 1" : "";
|