@portel/photon-core 2.5.3 → 2.5.4
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/compiler.d.ts.map +1 -1
- package/dist/compiler.js +61 -27
- package/dist/compiler.js.map +1 -1
- package/package.json +1 -1
- package/src/compiler.ts +75 -33
package/dist/compiler.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA2GH,wBAAsB,eAAe,CACnC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAC9C,OAAO,CAAC,MAAM,CAAC,CAmCjB"}
|
package/dist/compiler.js
CHANGED
|
@@ -19,40 +19,74 @@ import * as crypto from 'crypto';
|
|
|
19
19
|
* @returns Absolute path to the compiled .mjs file
|
|
20
20
|
*/
|
|
21
21
|
/**
|
|
22
|
-
* Transform
|
|
22
|
+
* Transform arrays to reactive collections for PhotonMCP classes
|
|
23
23
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
24
|
+
* ZERO-EFFORT REACTIVITY: If a class extends PhotonMCP and has array properties,
|
|
25
|
+
* this transform automatically:
|
|
26
|
+
* 1. Injects `import { Array as ReactiveArray } from '@portel/photon-core'`
|
|
27
|
+
* 2. Transforms `= []` to `= new ReactiveArray()` for class properties
|
|
28
28
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
29
|
+
* Result: Developers write normal code, arrays are automatically reactive.
|
|
30
|
+
*
|
|
31
|
+
* ```typescript
|
|
32
|
+
* // Developer writes this (normal TypeScript):
|
|
33
|
+
* export default class TodoList extends PhotonMCP {
|
|
34
|
+
* items: Task[] = [];
|
|
35
|
+
* async add(text: string) { this.items.push({...}); }
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* // Compiler transforms to:
|
|
39
|
+
* import { Array as ReactiveArray } from '@portel/photon-core';
|
|
40
|
+
* export default class TodoList extends PhotonMCP {
|
|
41
|
+
* items = new ReactiveArray();
|
|
42
|
+
* async add(text: string) { this.items.push({...}); } // Auto-emits!
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
31
45
|
*/
|
|
32
46
|
function transformReactiveCollections(source) {
|
|
33
|
-
// Check
|
|
34
|
-
const
|
|
35
|
-
if (!
|
|
47
|
+
// Check if this is a PhotonMCP class (extends PhotonMCP)
|
|
48
|
+
const isPhotonMCP = /class\s+\w+\s+extends\s+PhotonMCP\b/.test(source);
|
|
49
|
+
if (!isPhotonMCP)
|
|
50
|
+
return source;
|
|
51
|
+
// Check if there are array properties with = [] that need transformation
|
|
52
|
+
// Look for patterns like: `items: Type[] = []` or `items = []` (class properties)
|
|
53
|
+
const hasArrayLiterals = /\w+\s*:\s*[^=\n]+\[\]\s*=\s*\[\s*\]/.test(source) || // typed: Type[] = []
|
|
54
|
+
/^\s+\w+\s*=\s*\[\s*\](?=\s*[;\n])/m.test(source); // simple: prop = []
|
|
55
|
+
if (!hasArrayLiterals)
|
|
36
56
|
return source;
|
|
37
|
-
const imports = importMatch[1].split(',').map(s => s.trim());
|
|
38
57
|
let transformed = source;
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
//
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
58
|
+
// Check if Array is already imported from photon-core
|
|
59
|
+
const hasArrayImport = /import\s*\{[^}]*\bArray\b[^}]*\}\s*from\s*['"]@portel\/photon-core['"]/.test(source);
|
|
60
|
+
if (!hasArrayImport) {
|
|
61
|
+
// Inject ReactiveArray import (using alias to avoid shadowing issues)
|
|
62
|
+
// Find the photon-core import and add ReactiveArray to it, or add new import
|
|
63
|
+
const photonCoreImport = source.match(/import\s*\{([^}]+)\}\s*from\s*['"]@portel\/photon-core['"]/);
|
|
64
|
+
if (photonCoreImport) {
|
|
65
|
+
// Add to existing import
|
|
66
|
+
const existingImports = photonCoreImport[1];
|
|
67
|
+
transformed = transformed.replace(photonCoreImport[0], `import { ${existingImports}, Array as ReactiveArray } from '@portel/photon-core'`);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
// Add new import at the top (after any existing imports)
|
|
71
|
+
const lastImportMatch = source.match(/^import\s+.+$/gm);
|
|
72
|
+
if (lastImportMatch) {
|
|
73
|
+
const lastImport = lastImportMatch[lastImportMatch.length - 1];
|
|
74
|
+
transformed = transformed.replace(lastImport, `${lastImport}\nimport { Array as ReactiveArray } from '@portel/photon-core';`);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
// No imports, add at top
|
|
78
|
+
transformed = `import { Array as ReactiveArray } from '@portel/photon-core';\n${transformed}`;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
53
81
|
}
|
|
54
|
-
//
|
|
55
|
-
|
|
82
|
+
// Determine the Array constructor name to use
|
|
83
|
+
const arrayConstructor = hasArrayImport ? 'Array' : 'ReactiveArray';
|
|
84
|
+
// Transform class property declarations with type annotation = []
|
|
85
|
+
// Handles: items: Task[] = []; | items: Array<T> = [];
|
|
86
|
+
transformed = transformed.replace(/(\w+)\s*:\s*(?:Array<[^>]+>|[^=\n]+\[\])\s*=\s*\[\s*\]/g, `$1 = new ${arrayConstructor}()`);
|
|
87
|
+
// Transform class property without type annotation (indented, at start of line)
|
|
88
|
+
// Skip local variables (const/let/var)
|
|
89
|
+
transformed = transformed.replace(/^(\s+)(\w+)\s*=\s*\[\s*\](?=\s*[;\n])/gm, `$1$2 = new ${arrayConstructor}()`);
|
|
56
90
|
return transformed;
|
|
57
91
|
}
|
|
58
92
|
export async function compilePhotonTS(tsFilePath, options) {
|
package/dist/compiler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler.js","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC;;;;;;;GAOG;AACH
|
|
1
|
+
{"version":3,"file":"compiler.js","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC;;;;;;;GAOG;AACH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,SAAS,4BAA4B,CAAC,MAAc;IAClD,yDAAyD;IACzD,MAAM,WAAW,GAAG,qCAAqC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACvE,IAAI,CAAC,WAAW;QAAE,OAAO,MAAM,CAAC;IAEhC,yEAAyE;IACzE,kFAAkF;IAClF,MAAM,gBAAgB,GACpB,qCAAqC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,qBAAqB;QAC3E,oCAAoC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAK,oBAAoB;IAE7E,IAAI,CAAC,gBAAgB;QAAE,OAAO,MAAM,CAAC;IAErC,IAAI,WAAW,GAAG,MAAM,CAAC;IAEzB,sDAAsD;IACtD,MAAM,cAAc,GAAG,wEAAwE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE7G,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,sEAAsE;QACtE,6EAA6E;QAC7E,M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/photon-core",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.4",
|
|
4
4
|
"description": "Core library for parsing, loading, and managing .photon.ts files - runtime-agnostic foundation for building custom Photon runtimes",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
package/src/compiler.ts
CHANGED
|
@@ -21,52 +21,94 @@ import * as crypto from 'crypto';
|
|
|
21
21
|
* @returns Absolute path to the compiled .mjs file
|
|
22
22
|
*/
|
|
23
23
|
/**
|
|
24
|
-
* Transform
|
|
24
|
+
* Transform arrays to reactive collections for PhotonMCP classes
|
|
25
25
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
26
|
+
* ZERO-EFFORT REACTIVITY: If a class extends PhotonMCP and has array properties,
|
|
27
|
+
* this transform automatically:
|
|
28
|
+
* 1. Injects `import { Array as ReactiveArray } from '@portel/photon-core'`
|
|
29
|
+
* 2. Transforms `= []` to `= new ReactiveArray()` for class properties
|
|
30
30
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
31
|
+
* Result: Developers write normal code, arrays are automatically reactive.
|
|
32
|
+
*
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // Developer writes this (normal TypeScript):
|
|
35
|
+
* export default class TodoList extends PhotonMCP {
|
|
36
|
+
* items: Task[] = [];
|
|
37
|
+
* async add(text: string) { this.items.push({...}); }
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* // Compiler transforms to:
|
|
41
|
+
* import { Array as ReactiveArray } from '@portel/photon-core';
|
|
42
|
+
* export default class TodoList extends PhotonMCP {
|
|
43
|
+
* items = new ReactiveArray();
|
|
44
|
+
* async add(text: string) { this.items.push({...}); } // Auto-emits!
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
33
47
|
*/
|
|
34
48
|
function transformReactiveCollections(source: string): string {
|
|
35
|
-
// Check
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
);
|
|
39
|
-
if (!importMatch) return source;
|
|
49
|
+
// Check if this is a PhotonMCP class (extends PhotonMCP)
|
|
50
|
+
const isPhotonMCP = /class\s+\w+\s+extends\s+PhotonMCP\b/.test(source);
|
|
51
|
+
if (!isPhotonMCP) return source;
|
|
40
52
|
|
|
41
|
-
|
|
53
|
+
// Check if there are array properties with = [] that need transformation
|
|
54
|
+
// Look for patterns like: `items: Type[] = []` or `items = []` (class properties)
|
|
55
|
+
const hasArrayLiterals =
|
|
56
|
+
/\w+\s*:\s*[^=\n]+\[\]\s*=\s*\[\s*\]/.test(source) || // typed: Type[] = []
|
|
57
|
+
/^\s+\w+\s*=\s*\[\s*\](?=\s*[;\n])/m.test(source); // simple: prop = []
|
|
58
|
+
|
|
59
|
+
if (!hasArrayLiterals) return source;
|
|
42
60
|
|
|
43
61
|
let transformed = source;
|
|
44
62
|
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
63
|
+
// Check if Array is already imported from photon-core
|
|
64
|
+
const hasArrayImport = /import\s*\{[^}]*\bArray\b[^}]*\}\s*from\s*['"]@portel\/photon-core['"]/.test(source);
|
|
65
|
+
|
|
66
|
+
if (!hasArrayImport) {
|
|
67
|
+
// Inject ReactiveArray import (using alias to avoid shadowing issues)
|
|
68
|
+
// Find the photon-core import and add ReactiveArray to it, or add new import
|
|
69
|
+
const photonCoreImport = source.match(
|
|
70
|
+
/import\s*\{([^}]+)\}\s*from\s*['"]@portel\/photon-core['"]/
|
|
53
71
|
);
|
|
54
72
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
73
|
+
if (photonCoreImport) {
|
|
74
|
+
// Add to existing import
|
|
75
|
+
const existingImports = photonCoreImport[1];
|
|
76
|
+
transformed = transformed.replace(
|
|
77
|
+
photonCoreImport[0],
|
|
78
|
+
`import { ${existingImports}, Array as ReactiveArray } from '@portel/photon-core'`
|
|
79
|
+
);
|
|
80
|
+
} else {
|
|
81
|
+
// Add new import at the top (after any existing imports)
|
|
82
|
+
const lastImportMatch = source.match(/^import\s+.+$/gm);
|
|
83
|
+
if (lastImportMatch) {
|
|
84
|
+
const lastImport = lastImportMatch[lastImportMatch.length - 1];
|
|
85
|
+
transformed = transformed.replace(
|
|
86
|
+
lastImport,
|
|
87
|
+
`${lastImport}\nimport { Array as ReactiveArray } from '@portel/photon-core';`
|
|
88
|
+
);
|
|
89
|
+
} else {
|
|
90
|
+
// No imports, add at top
|
|
91
|
+
transformed = `import { Array as ReactiveArray } from '@portel/photon-core';\n${transformed}`;
|
|
64
92
|
}
|
|
65
|
-
|
|
93
|
+
}
|
|
66
94
|
}
|
|
67
95
|
|
|
68
|
-
//
|
|
69
|
-
|
|
96
|
+
// Determine the Array constructor name to use
|
|
97
|
+
const arrayConstructor = hasArrayImport ? 'Array' : 'ReactiveArray';
|
|
98
|
+
|
|
99
|
+
// Transform class property declarations with type annotation = []
|
|
100
|
+
// Handles: items: Task[] = []; | items: Array<T> = [];
|
|
101
|
+
transformed = transformed.replace(
|
|
102
|
+
/(\w+)\s*:\s*(?:Array<[^>]+>|[^=\n]+\[\])\s*=\s*\[\s*\]/g,
|
|
103
|
+
`$1 = new ${arrayConstructor}()`
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
// Transform class property without type annotation (indented, at start of line)
|
|
107
|
+
// Skip local variables (const/let/var)
|
|
108
|
+
transformed = transformed.replace(
|
|
109
|
+
/^(\s+)(\w+)\s*=\s*\[\s*\](?=\s*[;\n])/gm,
|
|
110
|
+
`$1$2 = new ${arrayConstructor}()`
|
|
111
|
+
);
|
|
70
112
|
|
|
71
113
|
return transformed;
|
|
72
114
|
}
|