-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use script-analyzed bindings when compiling template
- Loading branch information
Showing
14 changed files
with
192 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
module.exports = { | ||
root: true, | ||
extends: ['plugin:vue-libs/recommended'] | ||
extends: ['plugin:vue-libs/recommended'], | ||
rules: { | ||
indent: 'off', | ||
'space-before-function-paren': 'off' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,31 @@ | ||
const qs = require('querystring') | ||
const { attrsToQuery } = require('./utils') | ||
|
||
module.exports = function genCustomBlocksCode ( | ||
module.exports = function genCustomBlocksCode( | ||
blocks, | ||
resourcePath, | ||
resourceQuery, | ||
stringifyRequest | ||
) { | ||
return `\n/* custom blocks */\n` + blocks.map((block, i) => { | ||
const src = block.attrs.src || resourcePath | ||
const attrsQuery = attrsToQuery(block.attrs) | ||
const issuerQuery = block.attrs.src ? `&issuerPath=${qs.escape(resourcePath)}` : '' | ||
const inheritQuery = resourceQuery ? `&${resourceQuery.slice(1)}` : '' | ||
const query = `?vue&type=custom&index=${i}&blockType=${qs.escape(block.type)}${issuerQuery}${attrsQuery}${inheritQuery}` | ||
return ( | ||
`import block${i} from ${stringifyRequest(src + query)}\n` + | ||
`if (typeof block${i} === 'function') block${i}(component)` | ||
) | ||
}).join(`\n`) + `\n` | ||
return ( | ||
`\n/* custom blocks */\n` + | ||
blocks | ||
.map((block, i) => { | ||
const src = block.attrs.src || resourcePath | ||
const attrsQuery = attrsToQuery(block.attrs) | ||
const issuerQuery = block.attrs.src | ||
? `&issuerPath=${qs.escape(resourcePath)}` | ||
: '' | ||
const inheritQuery = resourceQuery ? `&${resourceQuery.slice(1)}` : '' | ||
const query = `?vue&type=custom&index=${i}&blockType=${qs.escape( | ||
block.type | ||
)}${issuerQuery}${attrsQuery}${inheritQuery}` | ||
return ( | ||
`import block${i} from ${stringifyRequest(src + query)}\n` + | ||
`if (typeof block${i} === 'function') block${i}(component)` | ||
) | ||
}) | ||
.join(`\n`) + | ||
`\n` | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const { resolveCompiler } = require('./compiler') | ||
|
||
const cache = new Map() | ||
|
||
exports.setDescriptor = function setDescriptor(filename, entry) { | ||
cache.set(cleanQuery(filename), entry) | ||
} | ||
|
||
exports.getDescriptor = function getDescriptor( | ||
filename, | ||
options, | ||
loaderContext | ||
) { | ||
filename = cleanQuery(filename) | ||
if (cache.has(filename)) { | ||
return cache.get(filename) | ||
} | ||
|
||
// This function should only be called after the descriptor has been | ||
// cached by the main loader. | ||
// If this is somehow called without a cache hit, it's probably due to sub | ||
// loaders being run in separate threads. The only way to deal with this is to | ||
// read from disk directly... | ||
const source = fs.readFileSync(filename, 'utf-8') | ||
const sourceRoot = path.dirname( | ||
path.relative(loaderContext.rootContext, loaderContext.resourcePath) | ||
) | ||
const { compiler, templateCompiler } = resolveCompiler( | ||
loaderContext.rootContext | ||
) | ||
const descriptor = compiler.parse({ | ||
source, | ||
compiler: options.compiler || templateCompiler, | ||
filename, | ||
sourceRoot, | ||
needMap: loaderContext.sourceMap | ||
}) | ||
cache.set(filename, descriptor) | ||
return descriptor | ||
} | ||
|
||
function cleanQuery(str) { | ||
const i = str.indexOf('?') | ||
return i > 0 ? str.slice(0, i) : str | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.