@vue/component-compiler-utils
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -0,1 +1,17 @@ | ||
<a name="2.1.0"></a> | ||
# [2.1.0](https://github.com/vuejs/component-compiler-utils/compare/v2.0.0...v2.1.0) (2018-07-03) | ||
### Bug Fixes | ||
* Forward preprocessor options to less ([#25](https://github.com/vuejs/component-compiler-utils/issues/25)) ([3b19c1e](https://github.com/vuejs/component-compiler-utils/commit/3b19c1e)), closes [#24](https://github.com/vuejs/component-compiler-utils/issues/24) | ||
* should work with variable named render (close [#23](https://github.com/vuejs/component-compiler-utils/issues/23)) ([273827b](https://github.com/vuejs/component-compiler-utils/commit/273827b)) | ||
### Features | ||
* Support `stylus` as `<style>` lang ([#18](https://github.com/vuejs/component-compiler-utils/issues/18)) ([986084e](https://github.com/vuejs/component-compiler-utils/commit/986084e)) | ||
<a name="2.0.0"></a> | ||
@@ -2,0 +18,0 @@ # [2.0.0](https://github.com/vuejs/component-compiler-utils/compare/v1.3.1...v2.0.0) (2018-06-03) |
@@ -18,7 +18,10 @@ "use strict"; | ||
return { | ||
code: (`var render = function () {}\n` + | ||
`var staticRenderFns = []\n`), | ||
code: `var render = function () {}\n` + `var staticRenderFns = []\n`, | ||
source: options.source, | ||
tips: [`Component ${options.filename} uses lang ${preprocessLang} for template. Please install the language preprocessor.`], | ||
errors: [`Component ${options.filename} uses lang ${preprocessLang} for template, however it is not installed.`] | ||
tips: [ | ||
`Component ${options.filename} uses lang ${preprocessLang} for template. Please install the language preprocessor.` | ||
], | ||
errors: [ | ||
`Component ${options.filename} uses lang ${preprocessLang} for template, however it is not installed.` | ||
] | ||
}; | ||
@@ -52,5 +55,3 @@ } | ||
const { source, compiler, compilerOptions = {}, transpileOptions = {}, transformAssetUrls, isProduction = process.env.NODE_ENV === 'production', isFunctional = false, optimizeSSR = false } = options; | ||
const compile = optimizeSSR && compiler.ssrCompile | ||
? compiler.ssrCompile | ||
: compiler.compile; | ||
const compile = optimizeSSR && compiler.ssrCompile ? compiler.ssrCompile : compiler.compile; | ||
let finalCompilerOptions = compilerOptions; | ||
@@ -65,3 +66,3 @@ if (transformAssetUrls) { | ||
finalCompilerOptions = Object.assign({}, compilerOptions, { | ||
modules: [...builtInModules, ...compilerOptions.modules || []] | ||
modules: [...builtInModules, ...(compilerOptions.modules || [])] | ||
}); | ||
@@ -72,4 +73,3 @@ } | ||
return { | ||
code: (`var render = function () {}\n` + | ||
`var staticRenderFns = []\n`), | ||
code: `var render = function () {}\n` + `var staticRenderFns = []\n`, | ||
source, | ||
@@ -91,4 +91,8 @@ tips, | ||
// version of Buble that applies ES2015 transforms + stripping `with` usage | ||
let code = transpile(`var render = ${toFunction(render)}\n` + | ||
`var staticRenderFns = [${staticRenderFns.map(toFunction)}]`, finalTranspileOptions) + `\n`; | ||
let code = transpile(`var __render__ = ${toFunction(render)}\n` + | ||
`var __staticRenderFns__ = [${staticRenderFns.map(toFunction)}]`, finalTranspileOptions) + `\n`; | ||
// #23 we use __render__ to avoid `render` not being prefixed by the | ||
// transpiler when stripping with, but revert it back to `render` to | ||
// maintain backwards compat | ||
code = code.replace(/\s__(render|staticRenderFns)__\s/g, ' $1 '); | ||
if (!isProduction) { | ||
@@ -95,0 +99,0 @@ // mark with stripped (this enables Vue to use correct runtime proxy |
@@ -60,3 +60,4 @@ "use strict"; | ||
if (/^(-\w+-)?animation-name$/.test(decl.prop)) { | ||
decl.value = decl.value.split(',') | ||
decl.value = decl.value | ||
.split(',') | ||
.map(v => keyframes[v.trim()] || v.trim()) | ||
@@ -67,3 +68,4 @@ .join(','); | ||
if (/^(-\w+-)?animation$/.test(decl.prop)) { | ||
decl.value = decl.value.split(',') | ||
decl.value = decl.value | ||
.split(',') | ||
.map(v => { | ||
@@ -70,0 +72,0 @@ const vals = v.trim().split(/\s+/); |
@@ -41,3 +41,3 @@ "use strict"; | ||
let error = null; | ||
nodeLess.render(source, { syncImport: true }, (err, output) => { | ||
nodeLess.render(source, Object.assign({}, options, { syncImport: true }), (err, output) => { | ||
error = err; | ||
@@ -86,3 +86,4 @@ result = output; | ||
scss, | ||
styl | ||
styl, | ||
stylus: styl | ||
}; |
@@ -29,3 +29,6 @@ "use strict"; | ||
// normal spaces, represented by escape sequences | ||
const [url, descriptor] = s.replace(escapedSpaceCharacters, ' ').trim().split(' ', 2); | ||
const [url, descriptor] = s | ||
.replace(escapedSpaceCharacters, ' ') | ||
.trim() | ||
.split(' ', 2); | ||
return { require: utils_1.urlToRequire(url), descriptor }; | ||
@@ -39,3 +42,8 @@ }); | ||
// "require(url1) 1x, require(url2) 2x" | ||
const code = imageCandidates.map(({ require, descriptor }) => `${require} + "${descriptor ? ' ' + descriptor : ''}, " + `).join('').slice(0, -6).concat('"').replace(/ \+ ""$/, ''); | ||
const code = imageCandidates | ||
.map(({ require, descriptor }) => `${require} + "${descriptor ? ' ' + descriptor : ''}, " + `) | ||
.join('') | ||
.slice(0, -6) | ||
.concat('"') | ||
.replace(/ \+ ""$/, ''); | ||
attr.value = code; | ||
@@ -42,0 +50,0 @@ } |
@@ -5,3 +5,7 @@ const postcss = require('postcss') | ||
import scopedPlugin from './stylePlugins/scoped' | ||
import { processors, StylePreprocessor, StylePreprocessorResults } from './styleProcessors' | ||
import { | ||
processors, | ||
StylePreprocessor, | ||
StylePreprocessorResults | ||
} from './styleProcessors' | ||
@@ -32,9 +36,9 @@ export interface StyleCompileOptions { | ||
export function compileStyle ( | ||
export function compileStyle( | ||
options: StyleCompileOptions | ||
): StyleCompileResults { | ||
): StyleCompileResults { | ||
return doCompileStyle({ ...options, isAsync: false }) | ||
} | ||
export function compileStyleAsync ( | ||
export function compileStyleAsync( | ||
options: StyleCompileOptions | ||
@@ -45,3 +49,3 @@ ): Promise<StyleCompileResults> { | ||
export function doCompileStyle ( | ||
export function doCompileStyle( | ||
options: AsyncStyleCompileOptions | ||
@@ -95,14 +99,18 @@ ): StyleCompileResults { | ||
return result | ||
.then((result: LazyResult): StyleCompileResults => ({ | ||
code: result.css || '', | ||
map: result.map && result.map.toJSON(), | ||
errors, | ||
rawResult: result | ||
})) | ||
.catch((error: Error): StyleCompileResults => ({ | ||
code: '', | ||
map: undefined, | ||
errors: [...errors, error.message], | ||
rawResult: undefined | ||
})) | ||
.then( | ||
(result: LazyResult): StyleCompileResults => ({ | ||
code: result.css || '', | ||
map: result.map && result.map.toJSON(), | ||
errors, | ||
rawResult: result | ||
}) | ||
) | ||
.catch( | ||
(error: Error): StyleCompileResults => ({ | ||
code: '', | ||
map: undefined, | ||
errors: [...errors, error.message], | ||
rawResult: undefined | ||
}) | ||
) | ||
} | ||
@@ -129,5 +137,12 @@ | ||
): StylePreprocessorResults { | ||
return preprocessor.render(options.source, options.map, Object.assign({ | ||
filename: options.filename | ||
}, options.preprocessOptions)) | ||
return preprocessor.render( | ||
options.source, | ||
options.map, | ||
Object.assign( | ||
{ | ||
filename: options.filename | ||
}, | ||
options.preprocessOptions | ||
) | ||
) | ||
} |
@@ -1,7 +0,6 @@ | ||
import { | ||
VueTemplateCompiler, | ||
VueTemplateCompilerOptions | ||
} from './types' | ||
import { VueTemplateCompiler, VueTemplateCompilerOptions } from './types' | ||
import assetUrlsModule, { AssetURLOptions } from './templateCompilerModules/assetUrl' | ||
import assetUrlsModule, { | ||
AssetURLOptions | ||
} from './templateCompilerModules/assetUrl' | ||
import srcsetModule from './templateCompilerModules/srcset' | ||
@@ -34,3 +33,3 @@ | ||
export function compileTemplate ( | ||
export function compileTemplate( | ||
options: TemplateCompileOptions | ||
@@ -41,15 +40,22 @@ ): TemplateCompileResult { | ||
if (preprocessor) { | ||
return actuallyCompile(Object.assign({}, options, { | ||
source: preprocess(options, preprocessor) | ||
})) | ||
return actuallyCompile( | ||
Object.assign({}, options, { | ||
source: preprocess(options, preprocessor) | ||
}) | ||
) | ||
} else if (preprocessLang) { | ||
return { | ||
code: ( | ||
`var render = function () {}\n` + | ||
`var staticRenderFns = []\n` | ||
), | ||
code: `var render = function () {}\n` + `var staticRenderFns = []\n`, | ||
source: options.source, | ||
tips: [`Component ${options.filename} uses lang ${preprocessLang} for template. Please install the language preprocessor.`], | ||
errors: [`Component ${options.filename} uses lang ${preprocessLang} for template, however it is not installed.`] | ||
}; | ||
tips: [ | ||
`Component ${ | ||
options.filename | ||
} uses lang ${preprocessLang} for template. Please install the language preprocessor.` | ||
], | ||
errors: [ | ||
`Component ${ | ||
options.filename | ||
} uses lang ${preprocessLang} for template, however it is not installed.` | ||
] | ||
} | ||
} else { | ||
@@ -60,16 +66,15 @@ return actuallyCompile(options) | ||
function preprocess ( | ||
function preprocess( | ||
options: TemplateCompileOptions, | ||
preprocessor: any | ||
): string { | ||
const { | ||
source, | ||
filename, | ||
const { source, filename, preprocessOptions } = options | ||
const finalPreprocessOptions = Object.assign( | ||
{ | ||
filename | ||
}, | ||
preprocessOptions | ||
} = options | ||
) | ||
const finalPreprocessOptions = Object.assign({ | ||
filename | ||
}, preprocessOptions) | ||
// Consolidate exposes a callback based API, but the callback is in fact | ||
@@ -93,3 +98,3 @@ // called synchronously for most templating engines. In our case, we have to | ||
function actuallyCompile ( | ||
function actuallyCompile( | ||
options: TemplateCompileOptions | ||
@@ -108,5 +113,4 @@ ): TemplateCompileResult { | ||
const compile = optimizeSSR && compiler.ssrCompile | ||
? compiler.ssrCompile | ||
: compiler.compile | ||
const compile = | ||
optimizeSSR && compiler.ssrCompile ? compiler.ssrCompile : compiler.compile | ||
@@ -122,19 +126,14 @@ let finalCompilerOptions = compilerOptions | ||
finalCompilerOptions = Object.assign({}, compilerOptions, { | ||
modules: [...builtInModules, ...compilerOptions.modules || []] | ||
modules: [...builtInModules, ...(compilerOptions.modules || [])] | ||
}) | ||
} | ||
const { | ||
render, | ||
staticRenderFns, | ||
tips, | ||
errors | ||
} = compile(source, finalCompilerOptions) | ||
const { render, staticRenderFns, tips, errors } = compile( | ||
source, | ||
finalCompilerOptions | ||
) | ||
if (errors && errors.length) { | ||
return { | ||
code: ( | ||
`var render = function () {}\n` + | ||
`var staticRenderFns = []\n` | ||
), | ||
code: `var render = function () {}\n` + `var staticRenderFns = []\n`, | ||
source, | ||
@@ -157,8 +156,14 @@ tips, | ||
// version of Buble that applies ES2015 transforms + stripping `with` usage | ||
let code = transpile( | ||
`var render = ${toFunction(render)}\n` + | ||
`var staticRenderFns = [${staticRenderFns.map(toFunction)}]`, | ||
finalTranspileOptions | ||
) + `\n` | ||
let code = | ||
transpile( | ||
`var __render__ = ${toFunction(render)}\n` + | ||
`var __staticRenderFns__ = [${staticRenderFns.map(toFunction)}]`, | ||
finalTranspileOptions | ||
) + `\n` | ||
// #23 we use __render__ to avoid `render` not being prefixed by the | ||
// transpiler when stripping with, but revert it back to `render` to | ||
// maintain backwards compat | ||
code = code.replace(/\s__(render|staticRenderFns)__\s/g, ' $1 ') | ||
if (!isProduction) { | ||
@@ -165,0 +170,0 @@ // mark with stripped (this enables Vue to use correct runtime proxy |
@@ -1,7 +0,2 @@ | ||
import { | ||
parse, | ||
SFCBlock, | ||
SFCCustomBlock, | ||
SFCDescriptor | ||
} from './parse' | ||
import { parse, SFCBlock, SFCCustomBlock, SFCDescriptor } from './parse' | ||
@@ -22,8 +17,3 @@ import { | ||
// API | ||
export { | ||
parse, | ||
compileTemplate, | ||
compileStyle, | ||
compileStyleAsync | ||
} | ||
export { parse, compileTemplate, compileStyle, compileStyleAsync } | ||
@@ -30,0 +20,0 @@ // types |
@@ -10,3 +10,3 @@ import { Root } from 'postcss' | ||
root.each(function rewriteSelector (node: any) { | ||
root.each(function rewriteSelector(node: any) { | ||
if (!node.selector) { | ||
@@ -47,5 +47,8 @@ // handle media queries | ||
}) | ||
selector.insertAfter(node, selectorParser.attribute({ | ||
attribute: id | ||
})) | ||
selector.insertAfter( | ||
node, | ||
selectorParser.attribute({ | ||
attribute: id | ||
}) | ||
) | ||
}) | ||
@@ -63,3 +66,4 @@ }).processSync(node.selector) | ||
if (/^(-\w+-)?animation-name$/.test(decl.prop)) { | ||
decl.value = decl.value.split(',') | ||
decl.value = decl.value | ||
.split(',') | ||
.map(v => keyframes[v.trim()] || v.trim()) | ||
@@ -70,3 +74,4 @@ .join(',') | ||
if (/^(-\w+-)?animation$/.test(decl.prop)) { | ||
decl.value = decl.value.split(',') | ||
decl.value = decl.value | ||
.split(',') | ||
.map(v => { | ||
@@ -73,0 +78,0 @@ const vals = v.trim().split(/\s+/) |
@@ -77,3 +77,3 @@ const merge = require('merge-source-map') | ||
source, | ||
{ syncImport: true }, | ||
Object.assign({}, options, { syncImport: true }), | ||
(err: Error | null, output: any) => { | ||
@@ -132,3 +132,4 @@ error = err | ||
scss, | ||
styl | ||
styl, | ||
stylus: styl | ||
} |
@@ -28,3 +28,3 @@ // vue compiler module for transforming `<tag>:<attribute>` to `require` | ||
function transform (node: ASTNode, options: AssetURLOptions) { | ||
function transform(node: ASTNode, options: AssetURLOptions) { | ||
for (const tag in options) { | ||
@@ -42,3 +42,3 @@ if ((tag === '*' || node.tag === tag) && node.attrs) { | ||
function rewrite (attr: Attr, name: string) { | ||
function rewrite(attr: Attr, name: string) { | ||
if (attr.name === name) { | ||
@@ -45,0 +45,0 @@ const value = attr.value |
@@ -27,3 +27,4 @@ // vue compiler module for transforming `img:srcset` to a number of `require`s | ||
const value = attr.value | ||
const isStatic = value.charAt(0) === '"' && value.charAt(value.length - 1) === '"' | ||
const isStatic = | ||
value.charAt(0) === '"' && value.charAt(value.length - 1) === '"' | ||
if (!isStatic) { | ||
@@ -33,4 +34,2 @@ return | ||
const imageCandidates: ImageCandidate[] = value | ||
@@ -42,3 +41,6 @@ .substr(1, value.length - 2) | ||
// normal spaces, represented by escape sequences | ||
const [url, descriptor] = s.replace(escapedSpaceCharacters, ' ').trim().split(' ', 2) | ||
const [url, descriptor] = s | ||
.replace(escapedSpaceCharacters, ' ') | ||
.trim() | ||
.split(' ', 2) | ||
return { require: urlToRequire(url), descriptor } | ||
@@ -53,5 +55,11 @@ }) | ||
// "require(url1) 1x, require(url2) 2x" | ||
const code = imageCandidates.map( | ||
({ require, descriptor }) => `${require} + "${descriptor ? ' ' + descriptor : ''}, " + ` | ||
).join('').slice(0, -6).concat('"').replace(/ \+ ""$/, '') | ||
const code = imageCandidates | ||
.map( | ||
({ require, descriptor }) => | ||
`${require} + "${descriptor ? ' ' + descriptor : ''}, " + ` | ||
) | ||
.join('') | ||
.slice(0, -6) | ||
.concat('"') | ||
.replace(/ \+ ""$/, '') | ||
@@ -58,0 +66,0 @@ attr.value = code |
@@ -11,3 +11,3 @@ export interface Attr { | ||
export function urlToRequire (url: string): string { | ||
export function urlToRequire(url: string): string { | ||
// same logic as in transform-require.js | ||
@@ -14,0 +14,0 @@ const firstChar = url.charAt(0) |
import { SFCDescriptor } from './parse' | ||
export interface StartOfSourceMap { | ||
file?: string; | ||
sourceRoot?: string; | ||
file?: string | ||
sourceRoot?: string | ||
} | ||
export interface RawSourceMap extends StartOfSourceMap { | ||
version: string; | ||
sources: string[]; | ||
names: string[]; | ||
sourcesContent?: string[]; | ||
mappings: string; | ||
version: string | ||
sources: string[] | ||
names: string[] | ||
sourcesContent?: string[] | ||
mappings: string | ||
} | ||
export interface VueTemplateCompiler { | ||
parseComponent( | ||
source: string, | ||
options?: any | ||
): SFCDescriptor | ||
parseComponent(source: string, options?: any): SFCDescriptor | ||
@@ -22,0 +19,0 @@ compile( |
{ | ||
"name": "@vue/component-compiler-utils", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Lower level utilities for compiling Vue single file components", | ||
@@ -8,6 +8,16 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"test": "jest", | ||
"lint": "prettier --write \"{lib,test}/**/*.ts\"", | ||
"test": "prettier --list-different \"{lib,test}/**/*.ts\" && jest", | ||
"build": "rm -rf dist && tsc", | ||
"prepublishOnly": "yarn build && conventional-changelog -p angular -r 2 -i CHANGELOG.md -s" | ||
}, | ||
"gitHooks": { | ||
"pre-commit": "lint-staged" | ||
}, | ||
"lint-staged": { | ||
"*.{ts,js}": [ | ||
"prettier --write", | ||
"git add" | ||
] | ||
}, | ||
"repository": { | ||
@@ -35,2 +45,3 @@ "type": "git", | ||
"less": "^3.0.1", | ||
"lint-staged": "^7.2.0", | ||
"node-sass": "^4.8.3", | ||
@@ -41,3 +52,4 @@ "pug": "^2.0.3", | ||
"typescript": "^2.7.2", | ||
"vue-template-compiler": "^2.5.16" | ||
"vue-template-compiler": "^2.5.16", | ||
"yorkie": "^1.0.3" | ||
}, | ||
@@ -51,3 +63,3 @@ "dependencies": { | ||
"postcss-selector-parser": "^3.1.1", | ||
"prettier": "^1.13.0", | ||
"prettier": "^1.13.7", | ||
"source-map": "^0.5.6", | ||
@@ -54,0 +66,0 @@ "vue-template-es2015-compiler": "^1.6.0" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57416
38
1484
13
Updatedprettier@^1.13.7