@danielx/civet 0.2.9 → 0.2.12

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
@@ -5,11 +5,18 @@ Civet
5
5
 
6
6
  A new CoffeeScript. Much closer to ES2015+ (for better or worse).
7
7
 
8
- Also TypeScript, the sky is the limit.
8
+ Also TypeScript, the sky is the limit. [Online Civet Playground](https://civet-web.vercel.app/)
9
+
10
+ Quickstart Guide
11
+ ---
9
12
 
10
13
  ```bash
14
+ # Install
11
15
  npm install -g @danielx/civet
16
+ # Compile civet source file to typescript
12
17
  civet < source.civet > output.ts
18
+ # Execute a civet source file in node
19
+ node --loader @danielx/civet/register.mjs source.civet
13
20
  ```
14
21
 
15
22
  ![image](https://user-images.githubusercontent.com/18894/184558519-b675a903-7490-43ba-883e-0d8addacd4b9.png)
@@ -20,7 +27,7 @@ Code Sample
20
27
  ```typescript
21
28
  import ts, {CompilerOptions} from "typescript"
22
29
 
23
- const DefaultCompilerOptions : CompilerOptions =
30
+ DefaultCompilerOptions : CompilerOptions :=
24
31
  allowNonTsExtensions: true
25
32
  allowJs: true
26
33
  target: ts.ScriptTarget.Latest
@@ -29,13 +36,13 @@ const DefaultCompilerOptions : CompilerOptions =
29
36
  allowSyntheticDefaultImports: true
30
37
  experimentalDecorators: true
31
38
 
32
- const fileCache : Record<string, any> = {}
39
+ fileCache : Record<string, any> := {}
33
40
 
34
- const createCompilerHost = (options: CompilerOptions, moduleSearchLocations : string[]) ->
35
- const fileExists = (fileName: string) : boolean ->
41
+ createCompilerHost := (options: CompilerOptions, moduleSearchLocations : string[]) ->
42
+ fileExists := (fileName: string) : boolean ->
36
43
  return fileCache[fileName]?
37
44
 
38
- const readFile = (fileName: string) ->
45
+ readFile := (fileName: string) ->
39
46
  return fileCache[fileName]
40
47
  ```
41
48
 
@@ -46,6 +53,8 @@ Things Kept from CoffeeScript
46
53
  - `or` -> `||`
47
54
  - `and` -> `&&`
48
55
  - `loop` -> `while(true)`
56
+ - `unless` conditional (without the `else`)
57
+ - `until condition` -> `while(!condition)`
49
58
  - Object literal syntax
50
59
  ```coffee
51
60
  x =
@@ -58,8 +67,8 @@ Things Kept from CoffeeScript
58
67
  - Optional semi-colons
59
68
  - Indentation based block syntax
60
69
  - OptionalChain shorthand for index and function application `a?[b]` -> `a?.[b]`, `a?(b)` -> `a?.(b)`
61
- - `@` -> `this`
62
- - `@id` -> `this.id`
70
+ - `@` This shorthand `@` -> `this`, `@id` -> `this.id`
71
+ - Prototype shorthand `X::` -> `X.prototype`, `X::a` -> `X.prototype.a`
63
72
  - Postfix `if/unless`
64
73
  - JSX 😿
65
74
  - TODO
@@ -70,14 +79,18 @@ Things Removed from CoffeeScript
70
79
  ---
71
80
 
72
81
  - `on/yes/off/no` (use `true/false`)
82
+ - `isnt` (use `!==`)
83
+ - `not` (use `!`)
73
84
  - `do` keyword (replaced with JS `do`)
74
85
  - `for from` (use JS `for of`)
75
86
  - Array slices `list[0...2]` (use `list.slice(0, 2)`)
87
+ - Slice assignment `numbers[3..6] = [-3, -4, -5, -6]`
76
88
  - Comprensions (a case could be made for keeping them)
77
89
  - Iteration expression results
78
90
  - Implicit declarations
79
91
  - Implicit returns (will probably add later)
80
92
  - Rest parameter in any assignment position (might add later)
93
+ - Postfix `while/until`
81
94
  - `///` Heregexp
82
95
  - Embedded JS
83
96
 
@@ -92,10 +105,15 @@ Things Changed from CoffeeScript
92
105
  - Existential `x?` -> `(x != null)` no longer checks for undeclared variables.
93
106
  - Embedded JS `\`\`` has been replaced with JS template literals.
94
107
  - No longer allowing multiple postfix `if/unless` on the same line.
108
+ - No `else` block on `unless` (negate condition and use `if`)
109
+ - Civet tries to keep the transpiled output verbatim as much as possible.
110
+ In Coffee `(x)` -> `x;` but in Civet `(x)` -> `(x);`.
111
+ Also in Coffee `x + 3` -> `x + 3` but in Civet `x + 3` remains as is.
95
112
 
96
113
  Things Added that CoffeeScript didn't
97
114
  ---
98
115
 
116
+ - TypeScript Types
99
117
  - JS Compatability
100
118
  - `var`, `let`, `const`
101
119
  - JS Comment Syntax `//` and `/* */`
@@ -103,8 +121,7 @@ Things Added that CoffeeScript didn't
103
121
  - OptionalChain longhand
104
122
  - ConditionalExpression
105
123
  - `case` statement
106
- - `while`
107
- - `do`
124
+ - `do`, `do { ... } until condition`
108
125
  - Const assignment shorthand `a := b` -> `const a = b`; `{a, b} := c` -> `const {a, b} = c`
109
126
  - Convenience for ES6+ Features
110
127
  - `<` as `extends` shorthand
@@ -112,17 +129,16 @@ Things Added that CoffeeScript didn't
112
129
  - ClassStaticBlock
113
130
  - `get`/`set` method definitions
114
131
  - Private identifiers `#id`
115
- - Shebang line
132
+ - Shebang line is kept unmodified in output
116
133
  ```civet
117
134
  #!./node_modules/.bin/ts-node
118
135
  console.log "hi"
119
136
  ```
120
- - TypeScript Types
121
137
 
122
138
  Things Changed from ES6
123
139
  ---
124
140
 
125
141
  - Disallow no parens on single argument arrow function. `x => ...` must become `(x) => ...`
126
- The reasoning is `x -> ` => `x(function() ...)` in CoffeeScript and having `->` and `=>`
142
+ The reasoning is `x -> ...` => `x(function() ...)` in CoffeeScript and having `->` and `=>`
127
143
  behave more differently than they already do is bad. Passing an anonymous function to an
128
144
  application without parens is also convenient.