From a89384c8d93a3e5a382f60a84d60f0675408ed75 Mon Sep 17 00:00:00 2001 From: sqal Date: Sun, 9 Dec 2018 21:42:20 +0100 Subject: [PATCH 001/503] test(ssr): add basic directives test (#9166) --- test/ssr/jasmine.js | 3 ++- test/ssr/ssr-string.spec.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/test/ssr/jasmine.js b/test/ssr/jasmine.js index dfd70f7c253..b632601642d 100644 --- a/test/ssr/jasmine.js +++ b/test/ssr/jasmine.js @@ -4,6 +4,7 @@ module.exports = { '*.spec.js' ], helpers: [ - require.resolve('@babel/register') + require.resolve('@babel/register'), + '../helpers/to-have-been-warned.js' ] } diff --git a/test/ssr/ssr-string.spec.js b/test/ssr/ssr-string.spec.js index a84c7267e08..4079c15e061 100644 --- a/test/ssr/ssr-string.spec.js +++ b/test/ssr/ssr-string.spec.js @@ -794,6 +794,23 @@ describe('SSR: renderToString', () => { }) }) + it('should resolve custom directive', done => { + renderToString(new Vue({ + directives: { + test: { + bind(node) { + node.data.domProps = { textContent: 'test' } + } + } + }, + template: '
', + }), (err, result) => { + expect('Failed to resolve directive: test').not.toHaveBeenWarned() + expect(result).toContain('
test
') + done() + }) + }) + it('custom directives', done => { const renderer = createRenderer({ directives: { From 780dac561b9cd6c3cec28f154f76e7d28352ebf3 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 9 Dec 2018 15:47:43 -0500 Subject: [PATCH 002/503] fix(ssr): should not warn for custom directives that do not have ssr implementation fix #9167 --- src/server/render.js | 2 +- test/ssr/ssr-string.spec.js | 33 ++++++++++++++++----------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/server/render.js b/src/server/render.js index 965b64febbb..581a6dfd52c 100644 --- a/src/server/render.js +++ b/src/server/render.js @@ -326,7 +326,7 @@ function renderStartingTag (node: VNode, context) { for (let i = 0; i < dirs.length; i++) { const name = dirs[i].name if (name !== 'show') { - const dirRenderer = resolveAsset(context, 'directives', name, true) + const dirRenderer = resolveAsset(context, 'directives', name) if (dirRenderer) { // directives mutate the node's data // which then gets rendered by modules diff --git a/test/ssr/ssr-string.spec.js b/test/ssr/ssr-string.spec.js index 4079c15e061..2f98bab8fae 100644 --- a/test/ssr/ssr-string.spec.js +++ b/test/ssr/ssr-string.spec.js @@ -794,23 +794,6 @@ describe('SSR: renderToString', () => { }) }) - it('should resolve custom directive', done => { - renderToString(new Vue({ - directives: { - test: { - bind(node) { - node.data.domProps = { textContent: 'test' } - } - } - }, - template: '
', - }), (err, result) => { - expect('Failed to resolve directive: test').not.toHaveBeenWarned() - expect(result).toContain('
test
') - done() - }) - }) - it('custom directives', done => { const renderer = createRenderer({ directives: { @@ -843,6 +826,22 @@ describe('SSR: renderToString', () => { }) }) + it('should not warn for custom directives that do not have server-side implementation', done => { + renderToString(new Vue({ + directives: { + test: { + bind() { + // noop + } + } + }, + template: '
', + }), () => { + expect('Failed to resolve directive: test').not.toHaveBeenWarned() + done() + }) + }) + it('_scopeId', done => { renderVmWithOptions({ _scopeId: '_v-parent', From 5d721a42b140865e50a78445fe21c5f270bde703 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 9 Dec 2018 15:52:17 -0500 Subject: [PATCH 003/503] revert: fix(sfc): avoid deindent when pad option is specified (#7647) This reverts commit 9d2f9a034f9c40d5ba6d8b1e131b1bfb675dc1cf. --- src/sfc/parser.js | 8 ++---- test/unit/modules/sfc/sfc-parser.spec.js | 33 +++++------------------- 2 files changed, 8 insertions(+), 33 deletions(-) diff --git a/src/sfc/parser.js b/src/sfc/parser.js index f6e83d362a3..d7868a40ab8 100644 --- a/src/sfc/parser.js +++ b/src/sfc/parser.js @@ -83,15 +83,11 @@ export function parseComponent ( function end (tag: string, start: number) { if (depth === 1 && currentBlock) { currentBlock.end = start - let text = content.slice(currentBlock.start, currentBlock.end) + let text = deindent(content.slice(currentBlock.start, currentBlock.end)) // pad content so that linters and pre-processors can output correct // line numbers in errors and warnings - if (options.pad) { + if (currentBlock.type !== 'template' && options.pad) { text = padContent(currentBlock, options.pad) + text - } else { - // avoid to deindent if pad option is specified - // to retain original source position. - text = deindent(text) } currentBlock.content = text currentBlock = null diff --git a/test/unit/modules/sfc/sfc-parser.spec.js b/test/unit/modules/sfc/sfc-parser.spec.js index 30a9f9e2c43..4cf6bad574a 100644 --- a/test/unit/modules/sfc/sfc-parser.spec.js +++ b/test/unit/modules/sfc/sfc-parser.spec.js @@ -71,42 +71,21 @@ describe('Single File Component parser', () => { const padLine = parseComponent(content.trim(), { pad: 'line' }) const padSpace = parseComponent(content.trim(), { pad: 'space' }) - expect(padDefault.template.content).toBe(Array(1).join('\n') + ` -
- `) - expect(padDefault.script.content).toBe(Array(3 + 1).join('//\n') + ` - export default {} - `) - expect(padDefault.styles[0].content).toBe(Array(6 + 1).join('\n') + ` - h1 { color: red } - `) - expect(padLine.template.content).toBe(Array(1).join('\n') + ` -
- `) - expect(padLine.script.content).toBe(Array(3 + 1).join('//\n') + ` - export default {} - `) - expect(padLine.styles[0].content).toBe(Array(6 + 1).join('\n') + ` - h1 { color: red } - `) - expect(padSpace.template.content).toBe(`