@panagos/jojoscript 0.7.0 → 0.7.1
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 +6 -6
- package/package.json +1 -1
- package/src/compiler.js +19 -2
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# JojoScript 0.7.
|
|
1
|
+
# JojoScript 0.7.1
|
|
2
2
|
|
|
3
3
|
JojoScript is a deliberately small source-to-source language that adds a
|
|
4
4
|
handful of ergonomic constructs on top of JavaScript while keeping ordinary
|
|
@@ -13,7 +13,7 @@ every feature described below.
|
|
|
13
13
|
## Install
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
npm install jojoscript
|
|
16
|
+
npm install @panagos/jojoscript
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
## CLI
|
|
@@ -252,11 +252,11 @@ return ids
|
|
|
252
252
|
```
|
|
253
253
|
|
|
254
254
|
`await`, `catch`, and `orElse` are resolved at compile time and are never
|
|
255
|
-
added to the automatic
|
|
255
|
+
added to the automatic `@panagos/jojoscript/runtime` import.
|
|
256
256
|
|
|
257
257
|
### Standard pipeline runtime
|
|
258
258
|
|
|
259
|
-
The following pipeline stages are supplied by
|
|
259
|
+
The following pipeline stages are supplied by `@panagos/jojoscript/runtime`. The
|
|
260
260
|
compiler automatically generates only the runtime imports that are actually
|
|
261
261
|
used through pipeline syntax (custom/user-defined stages are never
|
|
262
262
|
auto-imported):
|
|
@@ -336,12 +336,12 @@ import axios from "axios"
|
|
|
336
336
|
Generated JavaScript imports the runtime using the package subpath:
|
|
337
337
|
|
|
338
338
|
```js
|
|
339
|
-
import { map, take } from "jojoscript/runtime"
|
|
339
|
+
import { map, take } from "@panagos/jojoscript/runtime"
|
|
340
340
|
```
|
|
341
341
|
|
|
342
342
|
The package exposes this through `package.json` `exports`, so consumers
|
|
343
343
|
install `jojoscript` as a normal dependency. If a file both manually imports
|
|
344
|
-
from
|
|
344
|
+
from `@panagos/jojoscript/runtime` (for a stage that's only ever called directly,
|
|
345
345
|
never through `|>`) and also uses pipeline syntax with overlapping names,
|
|
346
346
|
the compiler merges the auto-imported names into the existing import
|
|
347
347
|
instead of emitting a second, colliding import declaration.
|
package/package.json
CHANGED
package/src/compiler.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
2
|
import path from 'node:path'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
3
4
|
|
|
4
5
|
import {
|
|
5
6
|
transformPipelines,
|
|
@@ -19,7 +20,17 @@ import {
|
|
|
19
20
|
import { transformMatchExpressions } from './match-parser.js'
|
|
20
21
|
import { transformTypeAnnotations } from './type-annotations.js'
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
/*
|
|
24
|
+
* The auto-generated runtime import must use whatever name this package is
|
|
25
|
+
* actually installed under (e.g. a scoped fork like "@me/jojoscript"), not a
|
|
26
|
+
* hardcoded literal, so it's derived from this package's own package.json
|
|
27
|
+
* instead of being hardcoded.
|
|
28
|
+
*/
|
|
29
|
+
const PACKAGE_ROOT = path.join(path.dirname(fileURLToPath(import.meta.url)), '..')
|
|
30
|
+
const OWN_PACKAGE_NAME = JSON.parse(
|
|
31
|
+
fs.readFileSync(path.join(PACKAGE_ROOT, 'package.json'), 'utf8')
|
|
32
|
+
).name
|
|
33
|
+
const JOJO_RUNTIME = `${OWN_PACKAGE_NAME}/runtime`
|
|
23
34
|
|
|
24
35
|
export function compile(source) {
|
|
25
36
|
let result = source
|
|
@@ -81,7 +92,13 @@ export function compile(source) {
|
|
|
81
92
|
return result.endsWith('\n') ? result : result + '\n'
|
|
82
93
|
}
|
|
83
94
|
|
|
84
|
-
const RUNTIME_IMPORT_PATTERN =
|
|
95
|
+
const RUNTIME_IMPORT_PATTERN = new RegExp(
|
|
96
|
+
`import\\s*\\{([^}]*)\\}\\s*from\\s*(["'])${escapeRegExp(JOJO_RUNTIME)}\\2`
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
function escapeRegExp(value) {
|
|
100
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
101
|
+
}
|
|
85
102
|
|
|
86
103
|
function mergeRuntimeImport(source, stdlibFunctions) {
|
|
87
104
|
const existing = source.match(RUNTIME_IMPORT_PATTERN)
|