@danielx/civet 0.7.9 → 0.7.11

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/dist/types.d.ts CHANGED
@@ -57,14 +57,21 @@ declare module "@danielx/civet" {
57
57
 
58
58
  // TODO: Import ParseError class from Hera
59
59
  export type ParseError = {
60
- message: string
61
- name: string
60
+ name: "ParseError"
61
+ message: string // filename:line:column header\nbody
62
+ header: string
63
+ body: string
62
64
  filename: string
63
65
  line: number
64
66
  column: number
65
67
  offset: number
66
68
  }
67
- export function isCompileError(err: any): err is ParseError
69
+ export type ParseErrors = {
70
+ name: "ParseErrors"
71
+ message: string
72
+ errors: ParseError[]
73
+ }
74
+ export function isCompileError(err: any): err is ParseError | ParseErrors
68
75
 
69
76
  type CompileOutput<T extends CompileOptions> =
70
77
  T extends { ast: true } ? CivetAST :
@@ -87,7 +94,7 @@ declare module "@danielx/civet" {
87
94
  isCompileError: typeof isCompileError
88
95
  parse: typeof parse
89
96
  generate: typeof generate
90
- util: {
97
+ sourcemap: {
91
98
  locationTable(input: string): number[]
92
99
  lookupLineColumn(table: number[], pos: number): [number, number]
93
100
  SourceMap(input: string): SourceMap
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
3
  "type": "commonjs",
4
- "version": "0.7.9",
4
+ "version": "0.7.11",
5
5
  "description": "CoffeeScript style syntax for TypeScript",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/main.mjs",
@@ -74,9 +74,9 @@
74
74
  "unplugin": "^1.6.0"
75
75
  },
76
76
  "devDependencies": {
77
- "@danielx/civet": "0.7.4",
78
- "@danielx/hera": "^0.8.13",
79
- "@prettier/sync": "^0.3.0",
77
+ "@danielx/civet": "0.7.10",
78
+ "@danielx/hera": "^0.8.14",
79
+ "@prettier/sync": "^0.5.2",
80
80
  "@types/assert": "^1.5.6",
81
81
  "@types/mocha": "^9.1.1",
82
82
  "@types/node": "^20.12.2",
@@ -84,7 +84,7 @@
84
84
  "esbuild": "0.20.0",
85
85
  "marked": "^4.2.4",
86
86
  "mocha": "^10.0.0",
87
- "prettier": "^3.1.1",
87
+ "prettier": "^3.2.5",
88
88
  "terser": "^5.16.1",
89
89
  "ts-node": "^10.9.1",
90
90
  "tslib": "^2.4.0",
package/register.js CHANGED
@@ -23,28 +23,56 @@ try {
23
23
  const { pathToFileURL } = require('node:url');
24
24
 
25
25
  register('./dist/esm.mjs', pathToFileURL(__filename));
26
- } catch (e) {}
26
+ } catch (e) {
27
+ // older Node lacking module register
28
+ }
27
29
 
28
- // CJS registration
29
- if (require.extensions) {
30
- const fs = require("fs");
31
- const { compile } = require("./");
30
+ const fs = require("fs");
31
+ const { compile } = require("./");
32
32
 
33
+ // Old-style CJS registration
34
+ if (require.extensions) {
33
35
  require.extensions[".civet"] = function (module, filename) {
34
36
  const js = compile(fs.readFileSync(filename, 'utf8'), {
35
37
  filename,
36
38
  js: true,
37
39
  inlineMap: true,
40
+ sync: true,
38
41
  });
39
42
  module._compile(js, filename);
40
43
  };
44
+ }
41
45
 
42
- try {
43
- require('@cspotcode/source-map-support').install({
44
- environment: 'node',
45
- hookRequire: true // support inline source maps
46
- })
47
- } catch (e) {
48
- // ignore missing dependency
46
+ const outputCache = new Map
47
+
48
+ function retrieveFile(path) {
49
+ if (!path.endsWith('.civet')) return
50
+
51
+ // If it's a file URL, convert to local path
52
+ // I could not find a way to handle non-URLs except to swallow an error
53
+ if (path.startsWith('file:')) {
54
+ try {
55
+ path = require('url').fileURLToPath(path)
56
+ } catch (e) {}
49
57
  }
58
+
59
+ if (!outputCache.has(path)) {
60
+ outputCache.set(path, compile(fs.readFileSync(path, 'utf8'), {
61
+ filename: path,
62
+ js: true,
63
+ inlineMap: true,
64
+ sync: true,
65
+ }));
66
+ }
67
+ return outputCache.get(path)
68
+ }
69
+
70
+ try {
71
+ require('@cspotcode/source-map-support').install({
72
+ environment: 'node',
73
+ hookRequire: true,
74
+ retrieveFile,
75
+ })
76
+ } catch (e) {
77
+ // ignore missing dependency
50
78
  }