ErrorCodes,
errorMessages,
createCompilerError,
+ defaultOnError,
+ defaultOnWarn,
type CoreCompilerError,
type CompilerError
} from './errors'
}
}
-export const DOMErrorMessages: { [code: number]: string } = {
+export const DOMErrorMessages: Record<DOMErrorCodes, string> = {
[DOMErrorCodes.X_V_HTML_NO_EXPRESSION]: `v-html is missing expression.`,
[DOMErrorCodes.X_V_HTML_WITH_CHILDREN]: `v-html will override element children.`,
[DOMErrorCodes.X_V_TEXT_NO_EXPRESSION]: `v-text is missing expression.`,
[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]: `<Transition> expects exactly one child element or component.`,
- [DOMErrorCodes.X_IGNORED_SIDE_EFFECT_TAG]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
+ [DOMErrorCodes.X_IGNORED_SIDE_EFFECT_TAG]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`,
+
+ // just to fulfill types
+ [DOMErrorCodes.__EXTEND_POINT__]: ``
}
-import { type RootNode, BindingTypes } from '@vue/compiler-dom'
-import {
- type CompilerOptions,
- VaporErrorCodes,
- compile as _compile,
-} from '../src'
+import { type RootNode, BindingTypes, ErrorCodes } from '@vue/compiler-dom'
+import { type CompilerOptions, compile as _compile } from '../src'
// TODO remove it
import { format } from 'prettier'
await compile(`<div v-bind:arg />`, { onError })
expect(onError.mock.calls[0][0]).toMatchObject({
- code: VaporErrorCodes.X_VAPOR_BIND_NO_EXPRESSION,
+ code: ErrorCodes.X_V_BIND_NO_EXPRESSION,
loc: {
start: {
line: 1,
const onError = vi.fn()
await compile(`<div v-on:click />`, { onError })
expect(onError.mock.calls[0][0]).toMatchObject({
- code: VaporErrorCodes.X_VAPOR_ON_NO_EXPRESSION,
+ code: ErrorCodes.X_V_ON_NO_EXPRESSION,
loc: {
start: {
line: 1,
type RootNode,
type DirectiveTransform,
parse,
+ defaultOnError,
+ createCompilerError,
+ ErrorCodes,
} from '@vue/compiler-dom'
import { extend, isString } from '@vue/shared'
import { NodeTransform, transform } from './transform'
import { generate } from './generate'
-import { defaultOnError, createCompilerError, VaporErrorCodes } from './errors'
import { transformOnce } from './transforms/vOnce'
import { HackOptions } from './hack'
/* istanbul ignore if */
if (__BROWSER__) {
if (options.prefixIdentifiers === true) {
- onError(createCompilerError(VaporErrorCodes.X_PREFIX_ID_NOT_SUPPORTED))
+ onError(createCompilerError(ErrorCodes.X_PREFIX_ID_NOT_SUPPORTED))
} else if (isModuleMode) {
- onError(createCompilerError(VaporErrorCodes.X_MODULE_MODE_NOT_SUPPORTED))
+ onError(createCompilerError(ErrorCodes.X_MODULE_MODE_NOT_SUPPORTED))
}
}
-import type { CompilerError } from '@vue/compiler-dom'
+import {
+ CompilerError,
+ SourceLocation,
+ createCompilerError,
+} from '@vue/compiler-dom'
-export { createCompilerError } from '@vue/compiler-dom'
-export function defaultOnError(error: CompilerError) {
- throw error
+export interface VaporCompilerError extends CompilerError {
+ code: VaporErrorCodes
}
-export function defaultOnWarn(msg: CompilerError) {
- __DEV__ && console.warn(`[Vue warn] ${msg.message}`)
+export function createVaporCompilerError(
+ code: VaporErrorCodes,
+ loc?: SourceLocation,
+) {
+ return createCompilerError(
+ code,
+ loc,
+ __DEV__ || !__BROWSER__ ? VaporErrorMessages : undefined,
+ ) as VaporCompilerError
}
export enum VaporErrorCodes {
- // transform errors
- X_VAPOR_BIND_NO_EXPRESSION,
- X_VAPOR_ON_NO_EXPRESSION,
-
- // generic errors
- X_PREFIX_ID_NOT_SUPPORTED,
- X_MODULE_MODE_NOT_SUPPORTED,
+ X_V_PLACEHOLDER = 100,
+ __EXTEND_POINT__,
}
-export const errorMessages: Record<VaporErrorCodes, string> = {
- // transform errors
- [VaporErrorCodes.X_VAPOR_BIND_NO_EXPRESSION]: `v-bind is missing expression.`,
- [VaporErrorCodes.X_VAPOR_ON_NO_EXPRESSION]: `v-on is missing expression.`,
+export const VaporErrorMessages: Record<VaporErrorCodes, string> = {
+ [VaporErrorCodes.X_V_PLACEHOLDER]: `[placeholder]`,
- [VaporErrorCodes.X_PREFIX_ID_NOT_SUPPORTED]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
- [VaporErrorCodes.X_MODULE_MODE_NOT_SUPPORTED]: `ES module mode is not supported in this build of compiler.`,
+ // just to fulfill types
+ [VaporErrorCodes.__EXTEND_POINT__]: ``,
}
type ExpressionNode,
type ParentNode,
type AllNode,
+ type CompilerCompatOptions,
NodeTypes,
BindingTypes,
- CompilerCompatOptions,
+ defaultOnError,
+ defaultOnWarn,
+ ErrorCodes,
+ createCompilerError,
} from '@vue/compiler-dom'
+import { EMPTY_OBJ, NOOP, isArray, isVoidTag } from '@vue/shared'
import {
type OperationNode,
type RootIRNode,
IRNodeTypes,
DynamicInfo,
} from './ir'
-import { EMPTY_OBJ, NOOP, isArray, isVoidTag } from '@vue/shared'
-import {
- VaporErrorCodes,
- createCompilerError,
- defaultOnError,
- defaultOnWarn,
-} from './errors'
-import { HackOptions } from './hack'
+import type { HackOptions } from './hack'
export type NodeTransform = (
node: RootNode | TemplateChildNode,
(exp.type === NodeTypes.SIMPLE_EXPRESSION && !exp.content.trim())
) {
ctx.options.onError!(
- createCompilerError(VaporErrorCodes.X_VAPOR_BIND_NO_EXPRESSION, loc),
+ createCompilerError(ErrorCodes.X_V_BIND_NO_EXPRESSION, loc),
)
return
}
case 'on': {
if (!exp && !modifiers.length) {
ctx.options.onError!(
- createCompilerError(VaporErrorCodes.X_VAPOR_ON_NO_EXPRESSION, loc),
+ createCompilerError(ErrorCodes.X_V_ON_NO_EXPRESSION, loc),
)
return
}
const resolve = (/** @type {string} */ p) =>
path.resolve(dirname, '../../packages', p)
-/** @returns {import('vite').Plugin} */
-export function DevPlugin() {
+/**
+ * @param {Object} [env]
+ * @param {boolean} [env.browser]
+ * @returns {import('vite').Plugin}
+ */
+export function DevPlugin({ browser = false } = {}) {
return {
name: 'dev-plugin',
config() {
// this is only used during Vue's internal tests
__TEST__: `false`,
// If the build is expected to run directly in the browser (global / esm builds)
- __BROWSER__: String(true),
+ __BROWSER__: String(browser),
__GLOBAL__: String(false),
__ESM_BUNDLER__: String(true),
__ESM_BROWSER__: String(false),