Skip to content

Commit a047515

Browse files
committed
Fixed bug with selects where they dont get set
1 parent 319d0b3 commit a047515

21 files changed

Lines changed: 750 additions & 36 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.0.13-prealpha",
2+
"version": "1.0.14-prealpha",
33
"description": "",
44
"main": "index.ts",
55
"type": "module",

packages/create-puls/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-pulsjs",
3-
"version": "1.0.13-prealpha",
3+
"version": "1.0.14-prealpha",
44
"main": "dist/index.js",
55
"scripts": {
66
"test": "echo \"Error: no test specified\" && exit 1",

packages/create-puls/template-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
"vite": "^6.1.0"
1313
},
1414
"dependencies": {
15-
"pulsjs": "1.0.13-prealpha"
15+
"pulsjs": "1.0.14-prealpha"
1616
}
1717
}

packages/create-puls/template-ts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
"vite": "^6.1.0"
1414
},
1515
"dependencies": {
16-
"pulsjs": "1.0.13-prealpha"
16+
"pulsjs": "1.0.14-prealpha"
1717
}
1818
}

packages/puls-adapter/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pulsjs-adapter",
3-
"version": "1.0.13-prealpha",
3+
"version": "1.0.14-prealpha",
44
"scripts": {
55
"test": "echo \"Error: no test specified\" && exit 1"
66
},

packages/puls-compiler/index.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
templateStringParse
77
} from "pulsjs-template";
88
import fs from "node:fs";
9+
import {Project} from "ts-morph";
910

1011
class RealValue {
1112
constructor(public value?: any) {
@@ -91,12 +92,31 @@ export async function compile(r: string) {
9192

9293
const promises: Promise<void>[] = []
9394

95+
let generic: string|undefined = undefined
96+
9497
templateParser.filterElements = (e: ParserTag) => {
9598
if (e.tag === 'script') {
9699
promises.push(new Promise<void>(async (res) => {
97100
const lang = e.attributes.find(([k]) => k === 'lang')?.[1]
98101

102+
generic = e.attributes.find(([k]) => k === 'generics')?.[1]
103+
99104
let scriptValue = (e.body[0] as ParserText).value
105+
106+
107+
const proj = new Project({
108+
useInMemoryFileSystem: true,
109+
})
110+
const sourceFile = proj.createSourceFile('example.ts', scriptValue)
111+
sourceFile.getImportDeclarations().forEach((imp) => {
112+
hasHtmlImport = hasHtmlImport || !!imp.getNamedImports().find(n => n.getName() === 'pulsInstance')
113+
extractedImports += imp.getFullText() + '\n'
114+
imp.remove()
115+
})
116+
117+
scriptValue = sourceFile.getFullText();
118+
119+
100120
if (lang === 'ts') {
101121
const ts = await import('typescript')
102122
const { outputText } = ts.transpileModule(scriptValue, {
@@ -106,20 +126,15 @@ export async function compile(r: string) {
106126
target: ts.ScriptTarget.ESNext,
107127
moduleResolution: ts.ModuleResolutionKind.NodeJs,
108128
esModuleInterop: true,
129+
noUnusedLocals: false,
130+
noUnusedParameters: false,
131+
allowUnusedLabels: true
109132
}
110133
})
111134
scriptValue = outputText;
112135
}
113136
scriptTag = scriptValue;
114137

115-
const importRegex = /import\s+(((?:type\s+)?(?:\*\s+as\s+\w+|{[^}]+}|\w+)\s+from\s+['"][^'"]+['"](?:\s+with\s+{[^}]+})?\s*)|(['"][^'"]+['"]));?/g;
116-
const imports = scriptTag.match(importRegex) || [];
117-
118-
hasHtmlImport = imports.some(i => /import\s+.*\bhtml\b.*from\s+['"]pulsInstance['"]/.test(i));
119-
120-
extractedImports = imports.join('\n');
121-
scriptTag = scriptTag.replace(importRegex, '').trim();
122-
123138
other = r.substring(0, e.from) + r.substring(e.to);
124139
res()
125140
}))
@@ -134,7 +149,7 @@ export async function compile(r: string) {
134149
const [strings, values] = parseTemplateString(other)
135150
const second = templateStringParse(new TemplateParser(), strings as any, ...values).parse();
136151

137-
return `${extractedImports}${hasHtmlImport ? '' : "\nimport { pulsInstance } from 'pulsjs';"}\n\nexport default ($props = {}) => {
152+
return `${extractedImports}${hasHtmlImport ? '' : "\nimport { pulsInstance } from 'pulsjs';"}\n/* ${generic ? `@template ${generic}` : ''} */\nexport default ($props = {}) => {
138153
\n ${scriptTag}\n \n return (new pulsInstance.adapter(${exportOutput(second)})).render();
139154
}`;
140155
}

packages/puls-compiler/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pulsjs-compiler",
3-
"version": "1.0.13-prealpha",
3+
"version": "1.0.14-prealpha",
44
"description": "",
55
"main": "dist/index.js",
66
"scripts": {
@@ -20,7 +20,8 @@
2020
"url": "git+https://github.com/interaapps/puls.git"
2121
},
2222
"dependencies": {
23-
"pulsjs-template": "workspace:*"
23+
"pulsjs-template": "workspace:*",
24+
"ts-morph": "^25.0.1"
2425
},
2526
"module": "dist/index.mjs",
2627
"exports": {

packages/puls-css/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pulsjs-css",
3-
"version": "1.0.13-prealpha",
3+
"version": "1.0.14-prealpha",
44
"scripts": {
55
"test": "echo \"Error: no test specified\" && exit 1"
66
},

packages/puls-dom-adapter/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pulsjs-dom-adapter",
3-
"version": "1.0.13-prealpha",
3+
"version": "1.0.14-prealpha",
44
"scripts": {
55
"test": "echo \"Error: no test specified\" && exit 1"
66
},

packages/puls-dom-adapter/src/PulsDOMAdapter.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
OnUnmounted,
88
PulsAdapter,
99
resetLifecycleHooks,
10-
currentLifecycleDefines, removeLifecycleHooksFromInstance
10+
currentLifecycleDefines,
11+
removeLifecycleHooksFromInstance
1112
} from "pulsjs-adapter";
1213

1314
export type ValueTransformer<T> = {
@@ -25,6 +26,8 @@ export class PulsDOMAdapter extends PulsAdapter<Node[]>{
2526

2627
inSVG = false
2728

29+
postRenderQueue: (() => void)[] = []
30+
2831
get document(): Document {
2932
return this.documentOverride ?? window.document
3033
}
@@ -96,10 +99,10 @@ export class PulsDOMAdapter extends PulsAdapter<Node[]>{
9699

97100
lifeCycleHooks.onMount.forEach((fn: OnMount) => fn())
98101

99-
lifeCycleComment.addEventListener(':attached', (e) => lifeCycleHooks.onMounted.forEach((fn: OnUnmount) => fn()))
102+
lifeCycleComment.addEventListener(':attached', (e) => lifeCycleHooks.onMounted.forEach((fn: OnMounted) => fn()))
100103
lifeCycleComment.addEventListener(':detach', () => lifeCycleHooks.onUnmount.forEach((fn: OnUnmount) => fn()))
101104
lifeCycleComment.addEventListener(':detached', () => {
102-
lifeCycleHooks.onUnmounted.forEach((fn: OnUnmount) => fn())
105+
lifeCycleHooks.onUnmounted.forEach((fn: OnUnmounted) => fn())
103106
})
104107
}
105108

@@ -451,6 +454,9 @@ export class PulsDOMAdapter extends PulsAdapter<Node[]>{
451454
}
452455

453456
render(): Node[] {
454-
return this.parsed.map(p => this.addPart(p)).flat().filter(c => c)
457+
this.postRenderQueue = []
458+
const result = this.parsed.map(p => this.addPart(p)).flat().filter(c => c)
459+
this.postRenderQueue.forEach(fn => fn())
460+
return result
455461
}
456462
}

0 commit comments

Comments
 (0)