text stringlengths 14 100k | source stringclasses 1
value | repo stringclasses 810
values | language stringclasses 13
values |
|---|---|---|---|
<|fim_prefix|>/**
* This Tokenizer is adapted from htmlparser2 under the MIT License listed at
* https://github.com/fb55/htmlparser2/blob/master/LICENSE
Copyright 2010, 2011, Chris Winberry <chris@winberry.net>. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this... | fim | vuejs/core | typescript |
<|fim_suffix|>oid {
let i = 0
const nodeRemoved = () => {
i--
}
for (; i < parent.children.length; i++) {
const child = parent.children[i]
if (isString(child)) continue
context.grandParent = context.parent
context.parent = parent
context.childIndex = i
context.onNodeRemoved = nodeRem... | fim | vuejs/core | typescript |
<|fim_suffix|>rent.codegenNode.type === NodeTypes.VNODE_CALL &&
parent.codegenNode.children &&
!isArray(parent.codegenNode.children) &&
parent.codegenNode.children.type === NodeTypes.JS_OBJECT_EXPRESSION
) {
// named <template> slot
const slotName = findDir(node, 'slot', true)
co... | fim | vuejs/core | typescript |
<|fim_prefix|>import type { <|fim_suffix|>onst noopDirectiveTransform: DirectiveTransform = () => ({ props: [] })
<|fim_middle|>DirectiveTransform } from '../transform'
export c<|endoftext|> | fim | vuejs/core | typescript |
<|fim_prefix|>import type { NodeTransform, TransformContext } from '../transform'
import {
type ArrayExpression,
type CallExpression,
type ComponentNode,
ConstantTypes,
type DirectiveArguments,
type DirectiveNode,
type ElementNode,
ElementTypes,
type ExpressionNode,
type JSChildNode,
NodeTypes,
... | fim | vuejs/core | typescript |
<|fim_suffix|> // source map support. (except for property keys which are static)
ids.push(node as QualifiedId)
}
},
true, // invoke on ALL identifiers
parentStack,
knownIds,
)
// We break up the compound expression into an array of strings and sub
// expressions (for identif... | fim | vuejs/core | typescript |
<|fim_suffix|> `$slots`,
slotName,
'{}',
'undefined',
'true',
]
let expectedLen = 2
if (slotProps) {
slotArgs[2] = slotProps
expectedLen = 3
}
if (children.length) {
slotArgs[3] = createFunctionExpression([], children, false, false, loc)
expectedLen ... | fim | vuejs/core | typescript |
<|fim_prefix|>import type { NodeTransform } from '../transform'
import {
type CallExpression,
type CompoundExpressionNode,
ConstantTypes,
ElementTypes,
NodeTypes,
createCallExpression,
createCompoundExpression,
} from '../ast'
import { isText } from '../utils'
import { CREATE_TEXT } from '../runtimeHelper... | fim | vuejs/core | typescript |
<|fim_prefix|>import { cameli<|fim_suffix|>CompilerError(
ErrorCodes.X_V_BIND_INVALID_SAME_NAME_ARGUMENT,
arg.loc,
),
)
prop.exp = createSimpleExpression('', true, arg.loc)
} else {
const propName = camelize((arg as SimpleExpressionNode).cont... | fim | vuejs/core | typescript |
<|fim_suffix|>&& !exp.content.trim()) {
if (!__BROWSER__) {
// #10280 only error against empty expression in non-browser build
// because :foo in in-DOM templates will be parsed into :foo="" by the
// browser
context.onError(
createCompilerError(ErrorCodes.X_V_BIND_NO_EXPRESSION, loc... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
type NodeTransform,
type TransformContext,
createStructuralDirectiveTransform,
} from '../transform'
import {
type BlockCodegenNode,
ConstantTypes,
type DirectiveNode,
type ElementNode,
type ExpressionNode,
type ForCodegenNode,
type ForIteratorExpression,
type ForNode,
typ... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
type NodeTransform,
type TransformContext,
createStructuralDirectiveTransform,
traverseNode,
} from '../transform'
import {
type AttributeNode,
type BlockCodegenNode,
type CacheExpression,
ConstantTypes,
type DirectiveNode,
type ElementNode,
ElementTypes,
type IfBranchNode... | fim | vuejs/core | typescript |
<|fim_suffix|>o')
if (!dir || seen.has(node) || context.inSSR) {
return
}
seen.add(node)
return () => {
const codegenNode =
node.codegenNode ||
(context.currentNode as PlainElementNode).codegenNode
if (codegenNode && codegenNode.type === NodeTypes.VNODE_CALL) {
... | fim | vuejs/core | typescript |
<|fim_prefix|>import type { DirectiveTransform } from '../transform'
import {
ConstantTypes,
ElementTypes,
type ExpressionNode,
NodeTypes,
type Property,
createCompoundExpression,
createObjectProperty,
createSimpleExpression,
} from '../ast'
import { ErrorCodes, createCompilerError } from '../errors'
im... | fim | vuejs/core | typescript |
import type { DirectiveTransform, DirectiveTransformResult } from '../transform'
import {
type DirectiveNode,
ElementTypes,
type ExpressionNode,
NodeTypes,
type SimpleExpressionNode,
createCompoundExpression,
createObjectProperty,
createSimpleExpression,
} from '../ast'
import { camelize, toHandlerKey }... | fim | vuejs/core | typescript |
<|fim_prefix|>import type { NodeTransform } from '../transform'
import { findDir } from '../utils'
import { type ElementNode, type ForNode, type IfNode, NodeTypes } from '../ast'
import { SET_BLOCK_TRACKING } from '../runtimeHelpers'
const seen = new WeakSet()
export const transformOnce: NodeTransform = (node, contex... | fim | vuejs/core | typescript |
import {
type CallExpression,
type ConditionalExpression,
type DirectiveNode,
type ElementNode,
ElementTypes,
type ExpressionNode,
type FunctionExpression,
NodeTypes,
type ObjectExpression,
type Property,
type SlotsExpression,
type SourceLocation,
type TemplateChildNode,
createArrayExpressio... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
type BlockCodegenNode,
type CacheExpression,
type CallExpression,
type DirectiveNode,
type ElementNode,
ElementTypes,
type ExpressionNode,
type IfBranchNode,
type InterpolationNode,
type JSChildNode,
type MemoExpression,
NodeTypes,
type ObjectExpression,
type Position,... | fim | vuejs/core | typescript |
<|fim_suffix|>st keywordMatch = exp
.replace(stripStringRE, '')
.match(prohibitedKeywordRE)
if (keywordMatch) {
message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`
}
context.onError(
createCompilerError(
ErrorCodes.X_INVALID_EXPRESSION,
n... | fim | vuejs/core | typescript |
<|fim_prefix|>/**
* @vitest-environment jsdom
*/
import { decodeHtmlBrowser } from '../src/decodeHtmlBrowser'
de<|fim_suffix|><|fim_middle|>scribe('decodeHtmlBrowser', () => {
it('should decode HTML correctly', () => {
expect(decodeHtmlBrowser(' abc 123 ')).toBe(' abc 123 ')
expect(decodeHtmlBrowser('&'... | fim | vuejs/core | typescript |
<|fim_prefix|>import { compile } from '../src'
describe('compile', () => {
it('should contain standard transforms', () => {
co<|fim_suffix|>or: 'green'}"></div>`)
expect(code).toMatchSnapshot()
})
})
<|fim_middle|>nst { code } = compile(`<div v-text="text"></div>
<div v-html="html"></div>
... | fim | vuejs/core | typescript |
<|fim_suffix|>lation = element.children[0] as InterpolationNode
expect(interpolation).toStrictEqual({
type: NodeTypes.INTERPOLATION,
content: {
type: NodeTypes.SIMPLE_EXPRESSION,
content: `a < b`,
isStatic: false,
constType: ConstantTypes.NOT_CONSTANT,
... | fim | vuejs/core | typescript |
<|fim_prefix|>import { compile } from '../../src'
describe('Transition multi children warnings', () => {
function checkWarning(
template: string,
shouldWarn: boolean,
message = `<Transition> expects exactly one child element or component.`,
) {
const spy = vi.fn()
compile(template.trim(), {
... | fim | vuejs/core | typescript |
<|fim_suffix|>h(`Tags with side effect`)
})
it('should ignore style', () => {
let err: CompilerError | undefined
const { code } = compile(`<style>h1 { color: red }</style>`, {
onError(e) {
err = e
},
})
expect(code).not.toMatch('style')
expect(err).toBeDefined()
expect(e... | fim | vuejs/core | typescript |
<|fim_suffix|>ligible content (elements > 20) + non-eligible content', () => {
const { code } = compileWithStringify(
`<div>${repeat(
`<span/>`,
StringifyThresholds.NODE_COUNT,
)}<div key="1">1</div>${repeat(
`<span/>`,
StringifyThresholds.NODE_COUNT,
)}</div>`,
... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
type CompilerOptions,
type ElementNode,
NodeTypes,
type VNodeCall,
baseParse as parse,
transform,
} from '@vue/compiler-core'
import { transformBind } from '../../../compiler-core/src/transforms/vBind'
import { transformElement } from '../../../compiler-core/src/transforms/transformEl... | fim | vuejs/core | typescript |
<|fim_suffix|>
const onError = vi.fn()
transformWithVHtml(`<div v-html></div>`, {
onError,
})
expect(onError.mock.calls).toMatchObject([
[{ code: DOMErrorCodes.X_V_HTML_NO_EXPRESSION }],
])
})
})
<|fim_prefix|>import {
type CompilerOptions,
type PlainElementNode,
baseParse as par... | fim | vuejs/core | typescript |
<|fim_suffix|>or input (radio)', () => {
const root = transformWithModel('<input type="radio" v-model="model" />')
expect(root.helpers).toContain(V_MODEL_RADIO)
expect(generate(root).code).toMatchSnapshot()
})
test('simple expression for input (checkbox)', () => {
const root = transformWithModel('... | fim | vuejs/core | typescript |
<|fim_suffix|>H_KEYS,
arguments: [{ content: '_ctx.test' }, '["left"]'],
},
})
})
it('should wrap both for dynamic key event w/ left/right modifiers', () => {
const {
props: [prop],
} = parseWithVOn(`<div @[e].left="test"/>`, {
prefixIdentifiers: true,
})
expect(prop).... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
type CompilerOptions,
generate,
baseParse as parse,
transform,
} from '@vue/compiler-core'
import { transformElement } from '../../../compiler-core/src/transforms/transformElement'
import { transformShow } from '../../src/transforms/vShow'
import { DOMErrorCodes } from '../../src/errors'
... | fim | vuejs/core | typescript |
<|fim_suffix|>PS,
dynamicProps: `["textContent"]`,
})
})
it('should raise error if has no expression', () => {
const onError = vi.fn()
transformWithVText(`<div v-text></div>`, {
onError,
})
expect(onError.mock.calls).toMatchObject([
[{ code: DOMErrorCodes.X_V_TEXT_NO_EXPRESSIO... | fim | vuejs/core | typescript |
<|fim_prefix|>import { type CompilerError, compile } from '../../src'
import { isValidHTMLNesting } from '../../src/htmlNesting'
describe('validate html nesting', () => {
it('should warn with p > div', () => {
let err: CompilerError | undefined
compile(`<p><div></div></p>`, {
onWarn: e => (err = e),
... | fim | vuejs/core | typescript |
<|fim_prefix|>'use strict'
if (process.env.NODE_ENV === 'production') {
module.<|fim_suffix|>s')
} else {
module.exports = require('./dist/compiler-dom.cjs.js')
}
<|fim_middle|>exports = require('./dist/compiler-dom.cjs.prod.j<|endoftext|> | fim | vuejs/core | javascript |
<|fim_prefix|>/* eslint-disable no-restricted-glo<|fim_suffix|>= `<div foo="${raw.replace(/"/g, '"')}">`
return decoder.children[0].getAttribute('foo')!
} else {
decoder.innerHTML = raw
return decoder.textContent!
}
}
<|fim_middle|>bals */
let decoder: HTMLDivElement
export function decodeHtmlBro... | fim | vuejs/core | typescript |
<|fim_suffix|>-model cannot be 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 e... | fim | vuejs/core | typescript |
<|fim_prefix|>/**
* Copied from https://github.com/MananTank/validate-html-nesting
* with ISC license
*
* To avoid runtime dependency on validate-html-nesting
* This file should not change very often in the original repo
* but we may need to keep it up-to-date from time to time.
*/
/**
* returns true if given ... | fim | vuejs/core | typescript |
<|fim_suffix|>ode fallback branches
ignoreSideEffectTags,
...DOMNodeTransforms,
...(options.nodeTransforms || []),
],
directiveTransforms: extend(
{},
DOMDirectiveTransforms,
options.directiveTransforms || {},
),
transformHoist: __BROWSER__ ? null ... | fim | vuejs/core | typescript |
<|fim_suffix|>tag === 'transition-group') {
return TRANSITION_GROUP
}
},
// https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
getNamespace(tag, parent, rootNamespace) {
let ns = parent ? parent.ns : rootNamespace
if (parent && ns === Namespaces.MATH_ML) {
if... | fim | vuejs/core | typescript |
<|fim_prefix|>import { registerRuntimeHelpers } from '@vue/compiler-core'
export<|fim_suffix|> __DEV__ ? `vOnKeysGuard` : ``,
)
export const V_SHOW: unique symbol = Symbol(__DEV__ ? `vShow` : ``)
export const TRANSITION: unique symbol = Symbol(__DEV__ ? `Transition` : ``)
export const TRANSITION_GROUP: unique symbo... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
type ComponentNode,
ElementTypes,
type IfBranchNode,
type NodeTransform,
NodeTypes,
isCommentOrWhitespace,
} from '@vue/compiler-core'
import { TRANSITION } from '../runtimeHelpers'
import { DOMErrorCodes, createDOMCompilerError } from '../errors'
export const transformTransition: No... | fim | vuejs/core | typescript |
<|fim_prefix|>import { ElementTypes, type NodeTransform, NodeTypes } from '@vue/compiler-core'
import { DOMErrorCodes, createDOMCompilerError } from '../errors'
export const ignoreSideEffectTags: NodeTransform = (node, context) => {
if (
node.type <|fim_suffix|> )
context.removeNode()
}
}
<|fim_middle|>=... | fim | vuejs/core | typescript |
<|fim_prefix|>/**
* This module is Node-only.
*/
import {
CREATE_STATIC,
type CacheExpression,
ConstantTypes,
type ElementNode,
ElementTypes,
type ExpressionNode,
type HoistTransform,
Namespaces,
NodeTypes,
type PlainElementNode,
type SimpleExpressionNode,
type TemplateChildNode,
type TextCa... | fim | vuejs/core | typescript |
<|fim_suffix|>: SimpleExpressionNode => {
const normalized = parseStringStyle(cssText)
return createSimpleExpression(
JSON.stringify(normalized),
false,
loc,
ConstantTypes.CAN_STRINGIFY,
)
}
<|fim_prefix|>import {
ConstantTypes,
type NodeTransform,
NodeTypes,
type SimpleExpressionNode,
t... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
type DirectiveTransform<|fim_suffix|>om '../errors'
export const transformVHtml: DirectiveTransform = (dir, node, context) => {
const { exp, loc } = dir
if (!exp) {
context.onError(
createDOMCompilerError(DOMErrorCodes.X_V_HTML_NO_EXPRESSION, loc),
)
}
if (node.children.l... | fim | vuejs/core | typescript |
<|fim_suffix|> call.
if (!isInvalidType) {
baseResult.needRuntime = context.helper(directiveToUse)
}
} else {
context.onError(
createDOMCompilerError(
DOMErrorCodes.X_V_MODEL_ON_INVALID_ELEMENT,
dir.loc,
),
)
}
// native vmodel doesn't need the `modelValue` props... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
CompilerDeprecationTypes,
type DirectiveTransform,
type ExpressionNode,
NodeTypes,
type SimpleExpressionNode,
type SourceLocation,
type TransformContext,
transformOn as baseTransform,
checkCompatEnabled,
createCallExpression,
createCompoundExpression,
createObjectProperty,... | fim | vuejs/core | typescript |
<|fim_prefix|>import type { DirectiveTransform } from '@vue/compile<|fim_suffix|> createDOMCompilerError(DOMErrorCodes.X_V_SHOW_NO_EXPRESSION, loc),
)
}
return {
props: [],
needRuntime: context.helper(V_SHOW),
}
}
<|fim_middle|>r-core'
import { DOMErrorCodes, createDOMCompilerError } from '../er... | fim | vuejs/core | typescript |
import {
type DirectiveTransform,
TO_DISPLAY_STRING,
createCallExpression,
createObjectProperty,
createSimpleExpression,
getConstantType,
} from '@vue/compiler-core'
import { DOMErrorCodes, createDOMCompilerError } from '../errors'
export const transformVText: DirectiveTransform = (dir, node, context) => {... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
type CompilerError,
ElementTypes,
type NodeTransform,
NodeTypes,
} from '@vue/compiler-core'
import { isValidH<|fim_suffix|>pes.ELEMENT &&
node.tagType === ElementTypes.ELEMENT &&
context.parent &&
context.parent.type === NodeTypes.ELEMENT &&
context.parent.tagType === Ele... | fim | vuejs/core | typescript |
<|fim_prefix|>import { BindingTypes } from '@vue/compiler-core'
import { assertCode, compileSFCScript as compile } from '../utils'
describe('defineEmits', () => {
test('basic usage', () => {
const { content, bindings } = compile(`
<script setup>
const myEmit = defineEmits(['foo', 'bar'])
</script>
`)
asser... | fim | vuejs/core | typescript |
<|fim_prefix|>import { assertCode, compileSFCScript as compile } from '../utils'
test('defineExpose()', () => {
const { content } = compile(`
<script setup>
defineExpose({ foo: 123 })
</script>
`)
assertCode(content)
// should remove defineOptions import and call
expect(content).not.toMatch('defineExpose')
/... | fim | vuejs/core | typescript |
<|fim_prefix|>import { BindingTypes } from '@vue/compiler-core'
import { assertCode, compileSFCScript as compile } from '../utils'
describe('defineModel()', () => {
test('basic usage', () => {
const { content, bindings } = compile(
`
<script setup>
const modelValue = defineModel({ required: tru... | fim | vuejs/core | typescript |
<|fim_suffix|>ad',
)
})
})
<|fim_prefix|>import { assertCode, compileSFCScript as compile } from '../utils'
describe('defineOptions()', () => {
test('basic usage', () => {
const { content } = compile(`
<script setup>
defineOptions({ name: 'FooApp' })
</script>
`)
assertCode(conten... | fim | vuejs/core | typescript |
<|fim_prefix|>import { BindingTypes } from '@vue/compiler-core'
import { assertCode, compileSFCScript as compile } from '../utils'
describe('defineProps', () => {
test('basic usage', () => {
const { content, bindings } = compile(`
<script setup>
const props = defineProps({
foo: String
})
const bar = 1
</script... | fim | vuejs/core | typescript |
<|fim_suffix|>);
</script>`)
expect(content).toMatch(`bar = foo`)
expect(content).toMatch(`var foo = "b"`)
expect(content).not.toMatch(`bar = __props.foo`)
assertCode(content)
})
test('var declaration shadowing before declaration in for loop', () => {
const { content } = compile(`<script setup ... | fim | vuejs/core | typescript |
import { assertCode, compileSFCScript as compile } from '../utils'
describe('defineSlots()', () => {
test('basic usage', () => {
const { content } = compile(`
<script setup lang="ts">
const slots = defineSlots<{
default: { msg: string }
}>()
</script>
`)
assertCode(content... | fim | vuejs/core | typescript |
<|fim_prefix|>import { BindingTypes } from '@vue/compiler-core'
import type { SFCScriptCompileOptions } from '../../src'
import { assertCode, compileSFCScript } from '../utils'
describe('sfc hoist static', () => {
function compile(src: string, options?: Partial<SFCScriptCompileOptions>) {
return compileSFCScript... | fim | vuejs/core | typescript |
<|fim_prefix|>import { assertCode, compileSFCScript as compile } from '../utils'
// in dev mode, declared bindings are returned as an object from setup()
// when using TS, users may import types which should not be returned as
// values, so we need to check import usage in the template to determine
// what to be retur... | fim | vuejs/core | typescript |
<|fim_suffix|>tEqual({
foo: ['String'],
})
})
test('generic type /w interface', () => {
expect(
resolve(`
interface Props<T> {
foo: T
}
type Foo = string
defineProps<Props<Foo>>()
`).props,
).toStrictEqual({
foo: ['String... | fim | vuejs/core | typescript |
<|fim_suffix|> `<script setup lang="ts">
const enum Foo { A = 123 }
</script>`,
{ hoistStatic: true },
)
assertCode(content)
expect(bindings).toStrictEqual({
Foo: BindingTypes.LITERAL_CONST,
})
})
test('import type', () => {
const { content } = ... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
type SFCStyleCompileOptions,
compileStyle,
compileStyleAsync,
} from '../src/compileStyle'
import path from 'node:path'
export function compileScoped(
source: string,
options?: Partial<SFCStyleCompileOptions>,
): string {
const res = compileStyle({
source,
filename: 'test.css... | fim | vuejs/core | typescript |
<|fim_suffix|> commentNode = code.match(/_createCommentVNode\("v-if", true\)/)
expect(commentNode).not.toBeNull()
const commentPosition = getPositionInCode(code, commentNode![0])
const originalPosition = consumer.originalPositionFor(commentPosition)
// the comment node should not be mapped to the original sourc... | fim | vuejs/core | typescript |
<|fim_prefix|>import { compileStyle, parse } from '../src'
import { assertCode, compileSFCScript, mockId } from './utils'
describe('CSS vars injection', () => {
test('generating correct code for nested paths', () => {
const { content } = compileSFCScript(
`<script>const a = 1</script>\n` +
`<style>... | fim | vuejs/core | typescript |
<|fim_suffix|>: 1, column: 9, offset: 8 },
end: { line: 1, column: 9, offset: 8 },
})
expect(descriptor.scriptSetup).toBeTruthy()
expect(descriptor.scriptSetup!.loc).toMatchObject({
start: { line: 2, column: 15, offset: 32 },
end: { line: 3, column: 1, offset: 33 },
})
})
test('n... | fim | vuejs/core | typescript |
<|fim_prefix|>import { rewriteDefault } from '../src'
describe('compiler sfc: rewriteDefault', () => {
test('without export default', () => {
expect(rewriteDefault(`export const a = {}`, 'script'))
.toMatchInlineSnapshot(`
"export const a = {}
const script = {}"
`)
})
test('rewrite exp... | fim | vuejs/core | typescript |
<|fim_suffix|>oo bar.png"/></div>`,
{
includeAbsolute: true,
},
{
hoistStatic: true,
transformHoist: stringifyStatic,
},
)
expect(code).toMatch(`_createElementVNode`)
expect(code).toContain(`import _imports_0 from './foo bar.png'`)
})
})
<|fim_prefix|>import... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
type TransformOptions,
baseParse,
generate,
transform,
} from '@vue/compiler-core'
import {
createSrcsetTransformWithOptions,
transformSrcset,
} from '../src/template/transformSrcset'
import { transformElement } from '../../compiler-core/src/transforms/transformElement'
import { trans... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
isDataUrl,
isExternalUrl,
isRelativeUrl,
} from '../src/template/templateUtils'
describe('compiler sfc:templateUtils isRelativeUrl', () => {
test('sho<|fim_suffix|>.toBe(true)
})
test('should return true when String starts with https://', () => {
const url = 'https://vuejs.org/'... | fim | vuejs/core | typescript |
import {
type SFCParseOptions,
type SFCScriptBlock,
type SFCScriptCompileOptions,
compileScript,
parse,
} from '../src'
import { parse as babelParse } from '@babel/parser'
export const mockId = 'xxxxxxxx'
export function compileSFCScript(
src: string,
options?: Partial<SFCScriptCompileOptions>,
parseO... | fim | vuejs/core | typescript |
<|fim_prefix|>import { LRUCache } from 'lru-cache'
export function createCache<T extends {}>(
max = 500,
): Map<string, T> | LRUCache<string, T> {
/<|fim_suffix|>turn new Map<string, T>()
}
return new LRUCache({ max })
}
<|fim_middle|>* v8 ignore next 3 */
if (__GLOBAL__ || __ESM_BROWSER__) {
re<|endofte... | fim | vuejs/core | typescript |
<|fim_suffix|>tate in sync.
// In inline mode, it generates `foo = $event`, which also requires `let`.
if (sfc.template && !sfc.template.src && sfc.template.ast) {
const vModelIds = resolveTemplateVModelIdentifiers(sfc)
if (vModelIds.size) {
const toDemote = new Set<string>()
for (const id of vM... | fim | vuejs/core | typescript |
import postcss, {
type LazyResult,
type Message,
type ProcessOptions,
type Result,
type SourceMap,
} from 'postcss'
import trimPlugin from './style/pluginTrim'
import scopedPlugin from './style/pluginScoped'
import {
type PreprocessLang,
type StylePreprocessor,
type StylePreprocessorResults,
processor... | fim | vuejs/core | typescript |
<|fim_suffix|>err
res = _res
},
)
if (err) throw err
return res
}
export function compileTemplate(
options: SFCTemplateCompileOptions,
): SFCTemplateCompileResults {
const { preprocessLang, preprocessCustomRequire } = options
if (
(__ESM_BROWSER__ || __GLOBAL__) &&
preprocessLang &&
... | fim | vuejs/core | typescript |
<|fim_suffix|>.0
* with reactivityTransform: true. The desired behavior should be silently
* ignoring the option instead of breaking.
*/
export const shouldTransformRef = () => false
<|fim_prefix|>export const version: string = __VERSION__
// API
export { parse } from './parse'
export { compileTemplate } from './co... | fim | vuejs/core | typescript |
import {
type BindingMetadata,
type CodegenSourceMapGenerator,
type CompilerError,
type ElementNode,
NodeTypes,
type ParserOptions,
type RawSourceMap,
type RootNode,
type SourceLocation,
createRoot,
} from '@vue/compiler-core'
import * as CompilerDOM from '@vue/compiler-dom'
import { SourceMapGenera... | fim | vuejs/core | typescript |
<|fim_suffix|> `import { ${s.slice(
specifier.local.start!,
specifier.local.end!,
)} as __VUE_DEFAULT__ } from '${node.source.value}'\n`,
)
const end = specifierEnd(s, specifier.exported.end!, node.end!)
s.remove(spec... | fim | vuejs/core | typescript |
<|fim_prefix|>import type {
ArrayExpression,
Node,
ObjectExpression,
Statement,
} from '@babel/types'
import { type BindingMetadata, BindingTypes } from '@vue/compiler-dom'
import { resolveObjectKey } from './utils'
/**
* Analyze bindings in normal `<script>`
* Note that `compileScriptSetup` already analyzes... | fim | vuejs/core | typescript |
<|fim_prefix|>import type { CallExpression, Node, ObjectPattern, Program } from '@babel/types'
import type { SFCDescriptor } from '../parse'
import { generateCodeFrame, isArray } from '@vue/shared'
import { type ParserPlugin, parse as babelParse } from '@babel/parser'
import type { ImportBinding, SFCScriptCompileOption... | fim | vuejs/core | typescript |
<|fim_prefix|>import type {
ArrayPattern,
Identifier,
LVal,
Node,
ObjectPattern,
RestElement,
} from '@babel/types'
import { isCallOf } from './utils'
import type { ScriptCompileContext } from './context'
import {
type TypeResolveContext,
resolveTypeElements,
resolveUnionType,
} from './resolveType'
... | fim | vuejs/core | typescript |
<|fim_prefix|>import type { Node } from '@babel/types'
import { isCallOf } from './utils'
impo<|fim_suffix|>E_EXPOSE}() call`, node)
}
ctx.hasDefineExposeCall = true
return true
}
return false
}
<|fim_middle|>rt type { ScriptCompileContext } from './context'
export const DEFINE_EXPOSE = 'defineExpose'
... | fim | vuejs/core | typescript |
<|fim_suffix|>++
ctx.s.remove(ctx.startOffset! + start, ctx.startOffset! + end)
// record prop options for invalid scope var reference check
runtimeOptionNodes.push(p)
}
}
if (removed === options.properties.length) {
optionsRemoved = true
ctx.s.remove(
ctx.start... | fim | vuejs/core | typescript |
<|fim_prefix|>import type { Node } from '@babel/types'
import { unwrapTSNode } from '@vue/compiler-dom'
import type { ScriptCompileContext } from './context'
import { isCallOf } from './utils'
import { DEFINE_PROPS } from './defineProps'
import { DEFINE_EMITS } from './defineEmits'
import { DEFINE_EXPOSE } from './defi... | fim | vuejs/core | typescript |
import type {
Expression,
LVal,
Node,
ObjectExpression,
ObjectMethod,
ObjectProperty,
} from '@babel/types'
import { BindingTypes, isFunctionType, unwrapTSNode } from '@vue/compiler-dom'
import type { ScriptCompileContext } from './context'
import {
type TypeResolveContext,
inferRuntimeType,
resolveTy... | fim | vuejs/core | typescript |
<|fim_prefix|>import type {
BlockStatement,
Expression,
Identifier,
Node,
ObjectPattern,
Program,
VariableDeclaration,
} from '@babel/types'
import { walk } from 'estree-walker'
import {
BindingTypes,
TS_NODE_TYPES,
extractIdentifiers,
isFunctionType,
isInDestructureAssignment,
isReferencedIde... | fim | vuejs/core | typescript |
<|fim_suffix|>overwrite(
ctx.startOffset! + node.start!,
ctx.startOffset! + node.end!,
`${ctx.helper('useSlots')}()`,
)
}
return true
}
<|fim_prefix|>import type { LVal, Node } from '@babel/types'
import { isCallOf } from './utils'
import type { ScriptCompileContext } from './context'
export... | fim | vuejs/core | typescript |
<|fim_prefix|>import type { SFCDescriptor } from '../parse'
import {
type ExpressionNode,
NodeTypes,
type SimpleExpressionNode,
type TemplateChildNode,
isSimpleIdentifier,
parserOptions,
walkIdentifiers,
} from '@vue/compiler-dom'
import { createCache } from '../cache'
import { camelize, capitalize, isBui... | fim | vuejs/core | typescript |
<|fim_suffix|>c-string'
import { rewriteDefaultAST } from '../rewriteDefault'
import { genNormalScriptCssVarsCode } from '../style/cssVars'
import type { SFCScriptBlock } from '../parse'
export const normalScriptDefaultVar = `__default__`
export function processNormalScript(
ctx: ScriptCompileContext,
scopeId: st... | fim | vuejs/core | typescript |
<|fim_prefix|>import type {
Expression,
Identifier,
Node,
Statement,
TSCallSignatureDeclaration,
TSEnumDeclaration,
TSExpressionWithTypeArguments,
TSFunctionType,
TSImportType,
TSIndexedAccessType,
TSInterfaceDeclaration,
TSMappedType,
TSMethodSignature,
TSModuleBlock,
TSModuleDeclaration,... | fim | vuejs/core | typescript |
<|fim_prefix|>import type { AwaitExpression } from '@babel/types'
import type { ScriptCompileContext } from './context'
/**
* Support context-<|fim_suffix|>oo())),
* await __temp,
* __restore()
* )
*
* // input
* const a = await foo()
* // output
* const a = (
* ([__temp, __restore] = withAsyncContext(... | fim | vuejs/core | typescript |
<|fim_prefix|>import type {
CallExpression,
Expression,
Identifier,
ImportDefaultSpecifier,
ImportNamespaceSpecifier,
ImportSpecifier,
Node,
StringLiteral,
TSMethodSignature,
TSPropertySignature,
} from '@babel/types'
import path from 'path'
export const UNKNOWN_TYPE = 'Unknown'
export function re... | fim | vuejs/core | typescript |
<|fim_prefix|>declare module 'mer<|fim_suffix|>object
}
<|fim_middle|>ge-source-map' {
export default function merge(oldMap: object, newMap: object): <|endoftext|> | fim | vuejs/core | typescript |
<|fim_suffix|> `initial` on the component instance to avoid unintentionally
// inheriting the same property value from a different instance of the same
// component in the outer scope.
`"${isSSR ? `:--` : ``}${genVarName(id, key, isProd, isSSR)}": (${key})`,
)
.join(',\n ')}\n}`
}
func... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
type AtRule,
type Container,
type Document,
type PluginCreator,
Rule,
} from 'postcss'
import selectorParser from 'postcss-selector-parser'
import { warn } from '../warn'
const animationNameRE = /^(?:-\w+-)?animation-name$/
const animationRE = /^(?:-\w+-)?animation$/
const keyframesRE ... | fim | vuejs/core | typescript |
<|fim_prefix|>import type { PluginCreator } from 'postcss'
const trimPlugin: PluginCreator<{}> = () => {
return <|fim_suffix|>'after' in raws && raws.after) raws.after = '\n'
}
})
},
}
}
trimPlugin.postcss = true
export default trimPlugin
<|fim_middle|>{
postcssPlugin: 'vue-sfc-trim',
On... | fim | vuejs/core | typescript |
<|fim_suffix|>s,
scss,
styl,
stylus: styl,
}
<|fim_prefix|>import merge from 'merge-source-map'
import type { RawSourceMap } from '@vue/compiler-core'
import type { SFCStyleCompileOptions } from '../compileStyle'
import { isFunction } from '@vue/shared'
export type StylePreprocessor = (
source: string,
map: ... | fim | vuejs/core | typescript |
<|fim_suffix|>secondChar === '/' ? 2 : 1)
}
return parseUriParts(url)
}
/**
* vuejs/component-compiler-utils#22 Support uri fragment in transformed require
* @param urlString - an url as a string
*/
function parseUriParts(urlString: string): UrlWithStringQuery {
// A TypeError is thrown if urlString is not a ... | fim | vuejs/core | typescript |
<|fim_suffix|>Types.CAN_STRINGIFY)
}
// Only hash without path - treat hash as the import source (likely a subpath import)
if (!path && hash) {
const { exp } = resolveOrRegisterImport(hash, loc, context)
return exp
}
// Only path without hash - straightforward import
if (path && !hash) {
const... | fim | vuejs/core | typescript |
<|fim_suffix|>es.CAN_STRINGIFY,
)
}
compoundExpression.children.push(exp)
}
} else {
const exp = createSimpleExpression(
`"${url}"`,
false,
attr.loc,
ConstantTypes.CA... | fim | vuejs/core | typescript |
<|fim_suffix|>] = true
warn(msg)
}
}
export function warn(msg: string): void {
console.warn(
`\x1b[1m\x1b[33m[@vue/compiler-sfc]\x1b[0m\x1b[33m ${msg}\x1b[0m\n`,
)
}
<|fim_prefix|>const hasWarned: Record<string, boolean> <|fim_middle|>= {}
export function warnOnce(msg: string): void {
const isNodeProd... | fim | vuejs/core | typescript |
<|fim_prefix|>import { compile } from '../src'
describe('ssr: components', () => {
test('basic', () => {
expect(compile(`<foo id="a" :prop="b" />`).code).toMatchInlineSnapshot(`
"const { resolveComponent: _resolveComponent, mergeProps: _mergeProps } = require("vue")
const { ssrRenderComponent: _ssrRe... | fim | vuejs/core | typescript |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.