From: Evan You Date: Wed, 8 Jul 2020 16:32:07 +0000 (-0400) Subject: fix(compiler-dom): should ignore and warn side effect tags like script and style X-Git-Tag: v3.0.0-beta.20~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5e52f4e4d7c92ee8ec9c0d644735e23342965096;p=thirdparty%2Fvuejs%2Fcore.git fix(compiler-dom): should ignore and warn side effect tags like script and style This keeps behavior consistency with v2. --- diff --git a/packages/compiler-dom/__tests__/transforms/ignoreSideEffectTags.spec.ts b/packages/compiler-dom/__tests__/transforms/ignoreSideEffectTags.spec.ts new file mode 100644 index 0000000000..4df6ee297f --- /dev/null +++ b/packages/compiler-dom/__tests__/transforms/ignoreSideEffectTags.spec.ts @@ -0,0 +1,27 @@ +import { compile, CompilerError } from '../../src' + +describe('compiler: ignore side effect tags', () => { + it('should ignore script', () => { + let err: CompilerError | undefined + const { code } = compile(``, { + onError(e) { + err = e + } + }) + expect(code).not.toMatch('script') + expect(err).toBeDefined() + expect(err!.message).toMatch(`Tags with side effect`) + }) + + it('should ignore style', () => { + let err: CompilerError | undefined + const { code } = compile(``, { + onError(e) { + err = e + } + }) + expect(code).not.toMatch('style') + expect(err).toBeDefined() + expect(err!.message).toMatch(`Tags with side effect`) + }) +}) diff --git a/packages/compiler-dom/src/errors.ts b/packages/compiler-dom/src/errors.ts index 1519324df2..44a0786008 100644 --- a/packages/compiler-dom/src/errors.ts +++ b/packages/compiler-dom/src/errors.ts @@ -31,6 +31,7 @@ export const enum DOMErrorCodes { X_V_MODEL_UNNECESSARY_VALUE, X_V_SHOW_NO_EXPRESSION, X_TRANSITION_INVALID_CHILDREN, + X_IGNORED_SIDE_EFFECT_TAG, __EXTEND_POINT__ } @@ -44,5 +45,6 @@ export const DOMErrorMessages: { [code: number]: string } = { [DOMErrorCodes.X_V_MODEL_ON_FILE_INPUT_ELEMENT]: `v-model cannot used on file inputs since they are read-only. Use a v-on:change listener instead.`, [DOMErrorCodes.X_V_MODEL_UNNECESSARY_VALUE]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`, [DOMErrorCodes.X_V_SHOW_NO_EXPRESSION]: `v-show is missing expression.`, - [DOMErrorCodes.X_TRANSITION_INVALID_CHILDREN]: ` expects exactly one child element or component.` + [DOMErrorCodes.X_TRANSITION_INVALID_CHILDREN]: ` expects exactly one child element or component.`, + [DOMErrorCodes.X_IGNORED_SIDE_EFFECT_TAG]: `Tags with side effect (