@danielx/civet 0.5.20 → 0.5.22

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
@@ -23,6 +23,8 @@ Quickstart Guide
23
23
  ```bash
24
24
  # Install
25
25
  npm install -g @danielx/civet
26
+ # Run civet code directly in a REPL
27
+ civet
26
28
  # Compile civet source file to typescript
27
29
  civet < source.civet > output.ts
28
30
  # Execute a civet source file in node using ts-node
@@ -140,6 +142,8 @@ Things Changed from CoffeeScript
140
142
  - `x?.y` now compiles to `x?.y` rather than the `if typeof x !== 'undefined' && x !== null` if check
141
143
  - Existential `x?` → `(x != null)` no longer checks for undeclared variables.
142
144
  - `x?()` → `x?.()` instead of `if (typeof x === 'function') { x() }`
145
+ - Functions don't implicitly return the last value if there's a semicolon
146
+ at the end: `-> x` returns `x` but `-> x;` does not
143
147
  - Backtick embedded JS has been replaced with JS template literals.
144
148
  - No longer allowing multiple postfix `if/unless` on the same line (use `&&` or `and` to combine conditions).
145
149
  - `#{}` interpolation in `""` strings only when `"civet coffeeCompat"` or `"civet coffeeInterpolation"`
@@ -310,6 +314,16 @@ You can use these with `"civet coffeeCompat"` to opt in to all or use them bit b
310
314
  Another possibility is to slowly remove them to provide a way to migrate files a little at a time `"civet coffeeCompat -coffeeBooleans -coffeeComment -coffeeEq"`.
311
315
  Both camel case and hyphens work when specifying options `"civet coffee-compat"`. More options will be added over time until 97+% compatibility is achieved.
312
316
 
317
+ ECMAScript Compatibility
318
+ ---
319
+
320
+ You can also specify `"civet"` prologue directives to increase
321
+ compatibility with ECMAScript/TypeScript:
322
+
323
+ | Configuration | What it enables |
324
+ |---------------------|---------------------------------------|
325
+ | -implicit-returns | turn off implicit return of last value in functions |
326
+
313
327
  Other Options
314
328
  ---
315
329
 
package/dist/browser.js CHANGED
@@ -441,6 +441,7 @@ ${input.slice(result.pos)}
441
441
  ParenthesizedExpression,
442
442
  ClassDeclaration,
443
443
  ClassExpression,
444
+ ClassBinding,
444
445
  ClassHeritage,
445
446
  ExtendsClause,
446
447
  ExtendsToken,
@@ -2204,7 +2205,7 @@ ${input.slice(result.pos)}
2204
2205
  return result;
2205
2206
  }
2206
2207
  }
2207
- var ClassExpression$0 = $TS($S($E(Decorators), $E($S(Abstract, __)), Class, $E($S(BindingIdentifier, $E(TypeParameters))), $E(ClassHeritage), ClassBody), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
2208
+ var ClassExpression$0 = $TS($S($E(Decorators), $E($S(Abstract, __)), Class, $E(ClassBinding), $E(ClassHeritage), ClassBody), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
2208
2209
  return $0;
2209
2210
  });
2210
2211
  function ClassExpression(state) {
@@ -2225,6 +2226,27 @@ ${input.slice(result.pos)}
2225
2226
  return result;
2226
2227
  }
2227
2228
  }
2229
+ var ClassBinding$0 = $T($S($N(EOS), BindingIdentifier, $E(TypeParameters)), function(value) {
2230
+ return [value[1], value[2]];
2231
+ });
2232
+ function ClassBinding(state) {
2233
+ if (state.events) {
2234
+ const result = state.events.enter?.("ClassBinding", state);
2235
+ if (result)
2236
+ return result.cache;
2237
+ }
2238
+ if (state.tokenize) {
2239
+ const result = $TOKEN("ClassBinding", state, ClassBinding$0(state));
2240
+ if (state.events)
2241
+ state.events.exit?.("ClassBinding", state, result);
2242
+ return result;
2243
+ } else {
2244
+ const result = ClassBinding$0(state);
2245
+ if (state.events)
2246
+ state.events.exit?.("ClassBinding", state, result);
2247
+ return result;
2248
+ }
2249
+ }
2228
2250
  var ClassHeritage$0 = $S(ExtendsClause, $E(ImplementsClause));
2229
2251
  var ClassHeritage$1 = ImplementsClause;
2230
2252
  function ClassHeritage(state) {
@@ -5303,7 +5325,7 @@ ${input.slice(result.pos)}
5303
5325
  ts: true
5304
5326
  };
5305
5327
  });
5306
- var MethodDefinition$1 = $TS($S(MethodSignature, BracedBlock), function($skip, $loc, $0, $1, $2) {
5328
+ var MethodDefinition$1 = $TS($S(MethodSignature, BracedOrEmptyBlock), function($skip, $loc, $0, $1, $2) {
5307
5329
  var signature = $1;
5308
5330
  var block = $2;
5309
5331
  return {
@@ -14634,6 +14656,8 @@ ${input.slice(result.pos)}
14634
14656
  insertBeforeAssignment(node, ["let ", undeclaredIdentifiers.join(", "), "\n"]);
14635
14657
  }
14636
14658
  } else if (node.type == "Declaration") {
14659
+ if (node.children && node.children.length)
14660
+ createLetDecs(node.children, scopes);
14637
14661
  node.names.forEach((name) => currentScope.add(name));
14638
14662
  } else {
14639
14663
  let block = node;
package/dist/civet CHANGED
@@ -186,6 +186,7 @@ cli = async function() {
186
186
  if (options.run) {
187
187
  options.js = true;
188
188
  options.inlineMap = true;
189
+ require("../register.js");
189
190
  }
190
191
  if (options.repl) {
191
192
  return repl(options);
@@ -247,8 +248,10 @@ cli = async function() {
247
248
  }
248
249
  }
249
250
  } else {
251
+ module.filename = await fs.realpath(filename);
252
+ module.paths = require("module")._nodeModulePaths(path.dirname(module.filename));
250
253
  try {
251
- results.push(require.main._compile(output, filename));
254
+ results.push(module._compile(output, module.filename));
252
255
  } catch (error1) {
253
256
  error = error1;
254
257
  console.error(`${filename} crashed while running:`);
package/dist/esm.mjs CHANGED
@@ -5,7 +5,7 @@ Currently depends on ts-node esm loader being downstream
5
5
 
6
6
  @example
7
7
  ```bash
8
- node --loader ts-node/esm --loader @danielx/civet/esm
8
+ node --loader ts-node/esm --loader @danielx/civet/esm source.civet
9
9
  ```
10
10
  */
11
11
 
package/dist/main.js CHANGED
@@ -440,6 +440,7 @@ ${input.slice(result.pos)}
440
440
  ParenthesizedExpression,
441
441
  ClassDeclaration,
442
442
  ClassExpression,
443
+ ClassBinding,
443
444
  ClassHeritage,
444
445
  ExtendsClause,
445
446
  ExtendsToken,
@@ -2203,7 +2204,7 @@ ${input.slice(result.pos)}
2203
2204
  return result;
2204
2205
  }
2205
2206
  }
2206
- var ClassExpression$0 = $TS($S($E(Decorators), $E($S(Abstract, __)), Class, $E($S(BindingIdentifier, $E(TypeParameters))), $E(ClassHeritage), ClassBody), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
2207
+ var ClassExpression$0 = $TS($S($E(Decorators), $E($S(Abstract, __)), Class, $E(ClassBinding), $E(ClassHeritage), ClassBody), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
2207
2208
  return $0;
2208
2209
  });
2209
2210
  function ClassExpression(state) {
@@ -2224,6 +2225,27 @@ ${input.slice(result.pos)}
2224
2225
  return result;
2225
2226
  }
2226
2227
  }
2228
+ var ClassBinding$0 = $T($S($N(EOS), BindingIdentifier, $E(TypeParameters)), function(value) {
2229
+ return [value[1], value[2]];
2230
+ });
2231
+ function ClassBinding(state) {
2232
+ if (state.events) {
2233
+ const result = state.events.enter?.("ClassBinding", state);
2234
+ if (result)
2235
+ return result.cache;
2236
+ }
2237
+ if (state.tokenize) {
2238
+ const result = $TOKEN("ClassBinding", state, ClassBinding$0(state));
2239
+ if (state.events)
2240
+ state.events.exit?.("ClassBinding", state, result);
2241
+ return result;
2242
+ } else {
2243
+ const result = ClassBinding$0(state);
2244
+ if (state.events)
2245
+ state.events.exit?.("ClassBinding", state, result);
2246
+ return result;
2247
+ }
2248
+ }
2227
2249
  var ClassHeritage$0 = $S(ExtendsClause, $E(ImplementsClause));
2228
2250
  var ClassHeritage$1 = ImplementsClause;
2229
2251
  function ClassHeritage(state) {
@@ -5302,7 +5324,7 @@ ${input.slice(result.pos)}
5302
5324
  ts: true
5303
5325
  };
5304
5326
  });
5305
- var MethodDefinition$1 = $TS($S(MethodSignature, BracedBlock), function($skip, $loc, $0, $1, $2) {
5327
+ var MethodDefinition$1 = $TS($S(MethodSignature, BracedOrEmptyBlock), function($skip, $loc, $0, $1, $2) {
5306
5328
  var signature = $1;
5307
5329
  var block = $2;
5308
5330
  return {
@@ -14633,6 +14655,8 @@ ${input.slice(result.pos)}
14633
14655
  insertBeforeAssignment(node, ["let ", undeclaredIdentifiers.join(", "), "\n"]);
14634
14656
  }
14635
14657
  } else if (node.type == "Declaration") {
14658
+ if (node.children && node.children.length)
14659
+ createLetDecs(node.children, scopes);
14636
14660
  node.names.forEach((name) => currentScope.add(name));
14637
14661
  } else {
14638
14662
  let block = node;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
- "version": "0.5.20",
3
+ "version": "0.5.22",
4
4
  "description": "CoffeeScript style syntax for TypeScript",
5
5
  "main": "dist/main.js",
6
6
  "exports": {
@@ -22,8 +22,9 @@
22
22
  },
23
23
  "scripts": {
24
24
  "build": "bash ./build/build.sh",
25
- "civet.dev": "bash ./build/site.sh",
26
- "npm-release": "bash ./build/npm-release.sh",
25
+ "docs:dev": "vitepress dev civet.dev",
26
+ "docs:build": "vitepress build civet.dev",
27
+ "docs:preview": "vitepress preview civet.dev",
27
28
  "prepublishOnly": "yarn build && yarn test",
28
29
  "test": "c8 mocha"
29
30
  },
@@ -35,6 +36,7 @@
35
36
  "@types/coffeescript": "^2.5.2",
36
37
  "@types/mocha": "^9.1.1",
37
38
  "@types/node": "^18.7.8",
39
+ "axios": "^1.2.2",
38
40
  "c8": "^7.12.0",
39
41
  "esbuild": "^0.14.49",
40
42
  "esbuild-coffeescript": "^2.1.0",
@@ -42,7 +44,9 @@
42
44
  "mocha": "^10.0.0",
43
45
  "ts-node": "^10.9.1",
44
46
  "tslib": "^2.4.0",
45
- "typescript": "^4.7.4"
47
+ "typescript": "^4.7.4",
48
+ "vitepress": "^1.0.0-alpha.35",
49
+ "vue": "^3.2.45"
46
50
  },
47
51
  "c8": {
48
52
  "all": true,
package/register.js CHANGED
@@ -1,10 +1,23 @@
1
+ /**
2
+ @file Civet CJS registration
3
+
4
+ `require`ing this file will register the `.civet` extension with
5
+ Node.js's `require`.
6
+
7
+ @example
8
+ ```bash
9
+ node -r @danielx/civet/register.js source.civet
10
+ ```
11
+ */
12
+
1
13
  if (require.extensions) {
2
14
  const fs = require("fs");
3
15
  const { compile } = require("./");
4
16
 
5
17
  require.extensions[".civet"] = function (module, filename) {
6
18
  const js = compile(fs.readFileSync(filename, 'utf8'), {
7
- js: true
19
+ js: true,
20
+ inlineMap: true,
8
21
  });
9
22
  module._compile(js, filename);
10
23
  return;
package/register.mjs DELETED
@@ -1,56 +0,0 @@
1
- import { readFileSync } from 'fs';
2
- import { readFile } from 'fs/promises';
3
- import { createRequire } from 'module';
4
- import { pathToFileURL, fileURLToPath } from 'url';
5
-
6
- import { compile } from "./dist/main.js";
7
-
8
- const baseURL = pathToFileURL(process.cwd() + '/').href;
9
- const extensionsRegex = /\.civet$/;
10
-
11
- export async function resolve(specifier, context, next) {
12
- const { parentURL = baseURL } = context;
13
-
14
- if (extensionsRegex.test(specifier)) {
15
- return {
16
- shortCircuit: true,
17
- format: "civet",
18
- url: new URL(specifier, parentURL).href,
19
- };
20
- }
21
-
22
- // Let Node.js handle all other specifiers.
23
- return next(specifier, context);
24
- }
25
-
26
- export async function load(url, context, next) {
27
- if (context.format === "civet") {
28
- const path = fileURLToPath(url)
29
- const source = await readFile(path, "utf8")
30
- const tsSource = compile(source, { filename: path })
31
-
32
- // NOTE: Assuming ts-node hook follows load hook
33
- // NOTE: This causes .civet files to show up as .ts in ts-node error reporting (TODO: May be able to add a sourcemapping)
34
- const result = await next(url.replace(extensionsRegex, ".tsx"), {
35
- // ts-node won't transpile unless this is module
36
- // can't use commonjs since we don't rewrite imports
37
- format: "module",
38
- // NOTE: Setting the source in the context makes it available when ts-node uses defaultLoad
39
- source: tsSource
40
- });
41
-
42
- return result
43
- }
44
-
45
- // Let Node.js handle all other URLs.
46
- return next(url, context);
47
- }
48
-
49
- const require = createRequire(import.meta.url);
50
- require.extensions[".civet"] = function (m, filename) {
51
- // We end up here when being required from cjs
52
- const source = readFileSync(filename, "utf8")
53
- const code = compile(source, { filename, js: true })
54
-
55
- m._compile(code, filename)
56
- }