Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fearure]:Support compileToSource to pass parameter fileContent for js files #169

Merged
merged 4 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,28 @@ writeFileSync('./dist/render-from-js.js', project.compileToSource('./component.j
render = require('./dist/render-from-js.js')
console.log(render(data))

// compile component.js to source(case2)
// Tips: in this case, your fileContent must strictly follow the writing rules
console.log('---- .js to Source Code(case2) ---')
writeFileSync('./dist/render-from-js2.js', project.compileToSource({
filePath: '__virtual.js',
fileContent: `const { defineComponent } = require('san')

module.exports = defineComponent({
computed: {
name: function () {
const f = this.data.get('firstName')
const l = this.data.get('lastName')
return f + ' ' + l
}
},
template: '<div><h1>{{name}}</h1></div>'
})
`
}))
render = require('./dist/render-from-js2.js')
console.log(render(data))

// compile component.san.html to source
console.log('---- .san to Source Code ---')
const dom = new JSDOM(readFileSync('./component.san.html'))
Expand Down
64 changes: 43 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/models/san-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
* CompileInput 可以是 JS、TS 源文件,也可以是组件类,得到的 SanSourceFile 里包含这个文件里
* San 相关的信息,比如有多少个组件?每个组件有哪些方法?以及得到 template 对应的 ANode 树。
*/
public parseSanSourceFile (componentClass: ComponentClass, options?: parseSanSourceFileOptions): DynamicSanSourceFile

Check warning on line 87 in src/models/san-project.ts

View workflow job for this annotation

GitHub Actions / Check (12)

This line has a length of 121. Maximum allowed is 120

Check warning on line 87 in src/models/san-project.ts

View workflow job for this annotation

GitHub Actions / Check (14)

This line has a length of 121. Maximum allowed is 120

Check warning on line 87 in src/models/san-project.ts

View workflow job for this annotation

GitHub Actions / Check (16)

This line has a length of 121. Maximum allowed is 120
public parseSanSourceFile (fileDescriptor: FileDescriptor, options?: parseSanSourceFileOptions): TypedSanSourceFile
public parseSanSourceFile (filecontent: string, options?: parseSanSourceFileOptions): JSSanSourceFile
public parseSanSourceFile (input: CompileInput, options?: parseSanSourceFileOptions): SanSourceFile
Expand All @@ -111,7 +111,7 @@
!fileContent && sourceFile.refreshFromFileSystemSync()
return new TypeScriptSanParser().parse(sourceFile, formattedOptions)
}
return new JavaScriptSanParser(filePath, formattedOptions).parse()
return new JavaScriptSanParser(filePath, formattedOptions, fileContent).parse()
}

private checkAndFormatParseSanSourceFileOptions (options?: parseSanSourceFileOptions)
Expand Down
Loading