Skip to content

Commit

Permalink
fix: dynamic component child with if
Browse files Browse the repository at this point in the history
  • Loading branch information
meixg committed Dec 22, 2021
1 parent f617087 commit 2dbc051
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ test/cases/*/output
/example
bin/output.js
bin/component*.js
bin/dist
44 changes: 26 additions & 18 deletions bin/debug-local.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
const { markExternalComponent, SanProject } = require('../dist/index')
const { markExternalComponent, SanProject, cancelMarkExternalComponent } = require('../dist/index')
const fs = require('fs')
const path = require('path')

markExternalComponent({
isExternalComponent (id) {
if (id === './search-ui') {
return true
function compile (componentPath, externalPath, outputPath) {
markExternalComponent({
isExternalComponent (id) {
if (id === externalPath) {
return true
}
}
}
})
})

// offline
const MyComponent = require('./component')
const sanProject = new SanProject()
const res = sanProject.compileToSource(MyComponent, 'js', {
useProvidedComponentClass: true
})
// offline
const MyComponent = require(componentPath)
const sanProject = new SanProject()
const res = sanProject.compileToSource(MyComponent, 'js', {
// useProvidedComponentClass: true
})

fs.writeFileSync(path.resolve(__dirname, './output.js'), res)
cancelMarkExternalComponent()

// online
const Component = require('./component')
const render = require('./output')
fs.writeFileSync(path.resolve(__dirname, outputPath), res)
}

const html = render({}, { ComponentClass: Component })
compile('./component', './component2', './dist/component')
// compile('./component2', './component', './dist/component2')

// // online
// const Component = require('./component')
const render = require('./dist/component')

const html = render({})
// const html = render({}, { ComponentClass: Component })

console.log(html)
12 changes: 6 additions & 6 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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"mkdirp": "^1.0.4",
"mustache": "^4.0.1",
"san": "^3.10.0",
"san-html-cases": "^3.10.22",
"san-html-cases": "^3.10.23",
"san-ssr-target-fake-cmd": "^1.0.0",
"san-ssr-target-fake-esm": "^1.0.0",
"semantic-release": "^17.4.4",
Expand Down
4 changes: 4 additions & 0 deletions src/compilers/anode-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ export class ANodeCompiler {

private * compileIf (aNode: AIfNode): Generator<Statement> {
const ifDirective = aNode.directives.if

// 动态节点 s-is 的子节点,会被编译两次。期间不能被修改。
// 这里复制一份。
const aNodeWithoutIf = Object.assign({}, aNode)
aNodeWithoutIf.directives = Object.assign({}, aNode.directives)

// 防止重新进入 compileIf:删掉 if 指令,再递归进入当前 aNode
// @ts-ignore
Expand Down

0 comments on commit 2dbc051

Please sign in to comment.