Skip to content

Commit

Permalink
Merge branch 'master' of github.com:NervJS/taro
Browse files Browse the repository at this point in the history
  • Loading branch information
Manjiz committed Jun 27, 2019
2 parents ff803ae + 14b135a commit 3b18f85
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 29 deletions.
44 changes: 23 additions & 21 deletions packages/taro-cli/src/h5/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,9 @@ class Compiler {
.on('unlink', filePath => {
const relativePath = path.relative(appPath, filePath)
const extname = path.extname(relativePath)
const distDirname = this.getTempDir(filePath)
const isScriptFile = REG_SCRIPTS.test(extname)
const dist = this.getDist(filePath, isScriptFile)
const dist = this.getDist(distDirname, filePath, isScriptFile)
printLog(processTypeEnum.UNLINK, '删除文件', relativePath)
fs.unlinkSync(dist)
})
Expand Down Expand Up @@ -267,7 +268,6 @@ class Compiler {
let hasComponentDidShow = false
let hasComponentDidHide = false
let hasComponentWillUnmount = false
let hasJSX = false
let hasNerv = false
let stateNode: t.ClassProperty

Expand Down Expand Up @@ -542,6 +542,7 @@ class Compiler {
}
}

// require('fs').writeFileSync('./ast.json', JSON.stringify(ast, null, 2))
traverse(ast, {
ClassExpression: ClassDeclarationOrExpression,
ClassDeclaration: ClassDeclarationOrExpression,
Expand Down Expand Up @@ -669,11 +670,6 @@ class Compiler {
}
}
},
JSXElement: {
enter (astPath: NodePath<t.JSXElement>) {
hasJSX = true
}
},
JSXOpeningElement: {
enter (astPath: NodePath<t.JSXOpeningElement>) {
const node = astPath.node
Expand Down Expand Up @@ -709,10 +705,10 @@ class Compiler {
createHistoryNode,
mountApisNode
]

astPath.traverse(programExitVisitor)

if (hasJSX && !hasNerv) {
/* Taro.render(<App />) 会被移除,导致hasJSX判断错误 */
if (!hasNerv) {
extraNodes.unshift(
t.importDeclaration(
[t.importDefaultSpecifier(t.identifier(nervJsImportDefaultName))],
Expand Down Expand Up @@ -887,9 +883,13 @@ class Compiler {
}
}
},
JSXElement: {
exit (astPath: NodePath<t.JSXElement>) {
hasJSX = true
}
},
JSXOpeningElement: {
exit (astPath: NodePath<t.JSXOpeningElement>) {
hasJSX = true
const node = astPath.node
const componentName = componentnameMap.get(toVar(node.name))
const componentId = getComponentId(componentName, node)
Expand Down Expand Up @@ -1143,16 +1143,23 @@ class Compiler {
}
}

processFiles (filePath) {
const sourceRoot = this.sourceRoot
getTempDir (filePath) {
const appPath = this.appPath
const sourcePath = this.sourcePath
const tempDir = this.tempDir

const file = fs.readFileSync(filePath)
const dirname = path.dirname(filePath)
const relPath = path.relative(sourcePath, dirname)

return path.resolve(appPath, tempDir, relPath)
}

processFiles (filePath) {
const file = fs.readFileSync(filePath)
const extname = path.extname(filePath)
const distDirname = dirname.replace(sourceRoot, tempDir)
const distDirname = this.getTempDir(filePath)
const isScriptFile = REG_SCRIPTS.test(extname)
const distPath = this.getDist(filePath, isScriptFile)
const distPath = this.getDist(distDirname, filePath, isScriptFile)

try {
if (isScriptFile) {
Expand All @@ -1179,12 +1186,7 @@ class Compiler {
}
}

getDist (filename, isScriptFile) {
const sourceRoot = this.sourceRoot
const tempDir = this.tempDir

const dirname = path.dirname(filename)
const distDirname = dirname.replace(sourceRoot, tempDir)
getDist (distDirname, filename, isScriptFile) {
return isScriptFile
? path.format({
dir: distDirname,
Expand Down
1 change: 1 addition & 0 deletions packages/taro-components/src/components/video/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class Video extends Component {
}

onLoadedMetadata = e => {
if (this.props.poster) return
this.setState({
duration: this.videoRef.duration
})
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-transformer-wx/src/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ class Transformer {
}

if (id.name.endsWith(CONTEXT_PROVIDER)) {
const valueAttr = path.node.openingElement.attributes.find(a => a.name.name === 'value')
const valueAttr = path.node.openingElement.attributes.find(a => t.isJSXIdentifier(a.name) && a.name.name === 'value')
const contextName = id.name.slice(0, id.name.length - CONTEXT_PROVIDER.length)
if (valueAttr) {
if (t.isJSXElement(valueAttr.value)) {
Expand Down
14 changes: 7 additions & 7 deletions packages/taro-transformer-wx/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ export class RenderParser {
}
}
const block = buildBlockElement()
const hasIfAttr = jsxElementPath.node.openingElement.attributes.find(a => a.name.name === Adapter.if)
const hasIfAttr = jsxElementPath.node.openingElement.attributes.find(a => t.isJSXIdentifier(a.name) && a.name.name === Adapter.if)
const needWrapper = Adapters.swan === Adapter.type && hasIfAttr
if (needWrapper) {
block.children = [jsxElementPath.node]
Expand Down Expand Up @@ -872,7 +872,7 @@ export class RenderParser {
newJSXIfAttr(jsxElementPath.node, test, jsxElementPath)
}
}
const ifAttr = block.openingElement.attributes.find(a => a.name.name === Adapter.if)
const ifAttr = block.openingElement.attributes.find(a => t.isJSXIdentifier(a.name) && a.name.name === Adapter.if)
if (ifAttr && t.isJSXExpressionContainer(ifAttr.value, { expression: test })) {
const newBlock = buildBlockElement()
newBlock.children = [block, jsxElementPath.node]
Expand All @@ -883,7 +883,7 @@ export class RenderParser {
let hasNest = false
this.handleNestedIfStatement(block, jsxElementPath.node, parentIfStatement.node.test, hasNest, isElse || !!ifStatement.findParent(p => p.node === parentIfStatement.node.alternate))
if (!hasNest && parentIfStatement.get('alternate') !== ifStatement) {
const ifAttr = block.openingElement.attributes.find(a => a.name.name === Adapter.if)
const ifAttr = block.openingElement.attributes.find(a => t.isJSXIdentifier(a.name) && a.name.name === Adapter.if)
if (ifAttr && t.isJSXExpressionContainer(ifAttr.value, { expression: parentIfStatement.node.test })) {
const newBlock = buildBlockElement()
block.children.push(jsxElementPath.node)
Expand Down Expand Up @@ -922,8 +922,8 @@ export class RenderParser {
if (!t.isJSXElement(child)) {
continue
}
const ifAttr = child.openingElement.attributes.find(a => a.name.name === Adapter.if)
const ifElseAttr = child.openingElement.attributes.find(a => a.name.name === Adapter.elseif)
const ifAttr = child.openingElement.attributes.find(a => t.isJSXIdentifier(a.name) && a.name.name === Adapter.if)
const ifElseAttr = child.openingElement.attributes.find(a => t.isJSXIdentifier(a.name) && a.name.name === Adapter.elseif)
if (
(ifAttr && t.isJSXExpressionContainer(ifAttr.value, { expression: test }))
||
Expand All @@ -946,8 +946,8 @@ export class RenderParser {
if (!t.isJSXElement(child)) {
continue
}
const ifAttr = child.openingElement.attributes.find(a => a.name.name === Adapter.if)
const ifElseAttr = child.openingElement.attributes.find(a => a.name.name === Adapter.elseif)
const ifAttr = child.openingElement.attributes.find(a => t.isJSXIdentifier(a.name) && a.name.name === Adapter.if)
const ifElseAttr = child.openingElement.attributes.find(a => t.isJSXIdentifier(a.name) && a.name.name === Adapter.elseif)
if (
(ifAttr && t.isJSXExpressionContainer(ifAttr.value, { expression: test }))
||
Expand Down

0 comments on commit 3b18f85

Please sign in to comment.