Skip to content

Commit eed7d1d

Browse files
committed
refactor(compiler-vapor): drop browser build
1 parent b1260e0 commit eed7d1d

File tree

11 files changed

+37
-56
lines changed

11 files changed

+37
-56
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"build-dts": "tsc -p tsconfig.build.json --noCheck && rollup -c rollup.dts.config.js",
1010
"clean": "rimraf --glob packages/*/dist temp .eslintcache",
1111
"size": "run-s \"size-*\" && node scripts/usage-size.js",
12-
"size-global": "node scripts/build.js vue vue-vapor runtime-dom runtime-vapor compiler-dom compiler-vapor -f global -p --size",
12+
"size-global": "node scripts/build.js vue vue-vapor runtime-dom runtime-vapor compiler-dom -f global -p --size",
1313
"size-esm-runtime": "node scripts/build.js vue vue-vapor -f esm-bundler-runtime",
1414
"size-esm": "node scripts/build.js runtime-shared runtime-dom runtime-vapor runtime-core reactivity shared -f esm-bundler",
1515
"check": "tsc --incremental --noEmit",

packages/compiler-vapor/index.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/compiler-vapor/package.json

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,28 @@
55
"main": "index.js",
66
"module": "dist/compiler-vapor.esm-bundler.js",
77
"types": "dist/compiler-vapor.d.ts",
8-
"unpkg": "dist/compiler-vapor.global.js",
9-
"jsdelivr": "dist/compiler-vapor.global.js",
108
"files": [
11-
"index.js",
129
"dist"
1310
],
1411
"sideEffects": false,
12+
"exports": {
13+
".": {
14+
"types": "./dist/compiler-vapor.d.ts",
15+
"node": "./dist/compiler-vapor.cjs.js",
16+
"module": "./dist/compiler-vapor.esm-browser.js",
17+
"import": "./dist/compiler-vapor.esm-browser.js",
18+
"require": "./dist/compiler-vapor.cjs.js"
19+
},
20+
"./*": "./*"
21+
},
1522
"buildOptions": {
1623
"name": "VueCompilerVapor",
17-
"compat": true,
1824
"formats": [
19-
"esm-bundler",
20-
"esm-browser",
2125
"cjs",
22-
"global"
23-
]
26+
"esm-browser"
27+
],
28+
"prod": false,
29+
"enableNonBrowserBranches": true
2430
},
2531
"repository": {
2632
"type": "git",

packages/compiler-vapor/src/compile.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,7 @@ export function compile(
4040
): VaporCodegenResult {
4141
const onError = options.onError || defaultOnError
4242
const isModuleMode = options.mode === 'module'
43-
/* istanbul ignore if */
44-
if (__BROWSER__) {
45-
if (options.prefixIdentifiers === true) {
46-
onError(createCompilerError(ErrorCodes.X_PREFIX_ID_NOT_SUPPORTED))
47-
} else if (isModuleMode) {
48-
onError(createCompilerError(ErrorCodes.X_MODULE_MODE_NOT_SUPPORTED))
49-
}
50-
}
51-
52-
const prefixIdentifiers =
53-
!__BROWSER__ && (options.prefixIdentifiers === true || isModuleMode)
43+
const prefixIdentifiers = options.prefixIdentifiers === true || isModuleMode
5444

5545
if (options.scopeId && !isModuleMode) {
5646
onError(createCompilerError(ErrorCodes.X_SCOPE_ID_NOT_SUPPORTED))
@@ -63,7 +53,7 @@ export function compile(
6353
const [nodeTransforms, directiveTransforms] =
6454
getBaseTransformPreset(prefixIdentifiers)
6555

66-
if (!__BROWSER__ && options.isTS) {
56+
if (options.isTS) {
6757
const { expressionPlugins } = options
6858
if (!expressionPlugins || !expressionPlugins.includes('typescript')) {
6959
resolvedOptions.expressionPlugins = [

packages/compiler-vapor/src/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function createVaporCompilerError(
1515
return createCompilerError(
1616
code,
1717
loc,
18-
__DEV__ || !__BROWSER__ ? VaporErrorMessages : undefined,
18+
VaporErrorMessages,
1919
) as VaporCompilerError
2020
}
2121

packages/compiler-vapor/src/generators/expression.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export function genExpression(
2828
}
2929

3030
if (
31-
__BROWSER__ ||
3231
!prefixIdentifiers ||
3332
!node.content.trim() ||
3433
// there was a parsing error

packages/compiler-vapor/src/generators/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export function codeFragmentToString(
102102
} = context
103103

104104
let map: CodegenSourceMapGenerator | undefined
105-
if (!__BROWSER__ && sourceMap) {
105+
if (sourceMap) {
106106
// lazy require source-map implementation, only in non-browser builds
107107
map = new SourceMapGenerator() as unknown as CodegenSourceMapGenerator
108108
map.setSourceContent(filename, context.ir.source)
@@ -136,7 +136,7 @@ export function codeFragmentToString(
136136
let [code, newlineIndex = NewlineType.None, loc, name] = frag
137137
codegen += code
138138

139-
if (!__BROWSER__ && map) {
139+
if (map) {
140140
if (loc) addMapping(loc.start, name)
141141
if (newlineIndex === NewlineType.Unknown) {
142142
// multiple newlines, full iteration

packages/compiler-vapor/src/transforms/transformElement.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,21 @@ function transformComponentElement(
7474
) {
7575
let asset = true
7676

77-
if (!__BROWSER__) {
78-
const fromSetup = resolveSetupReference(tag, context)
79-
if (fromSetup) {
80-
tag = fromSetup
77+
const fromSetup = resolveSetupReference(tag, context)
78+
if (fromSetup) {
79+
tag = fromSetup
80+
asset = false
81+
}
82+
83+
const dotIndex = tag.indexOf('.')
84+
if (dotIndex > 0) {
85+
const ns = resolveSetupReference(tag.slice(0, dotIndex), context)
86+
if (ns) {
87+
tag = ns + tag.slice(dotIndex)
8188
asset = false
8289
}
83-
const dotIndex = tag.indexOf('.')
84-
if (dotIndex > 0) {
85-
const ns = resolveSetupReference(tag.slice(0, dotIndex), context)
86-
if (ns) {
87-
tag = ns + tag.slice(dotIndex)
88-
asset = false
89-
}
90-
}
9190
}
91+
9292
if (asset) {
9393
context.component.add(tag)
9494
}
@@ -304,8 +304,7 @@ function transformProp(
304304
}
305305

306306
if (!isBuiltInDirective(name)) {
307-
const fromSetup =
308-
!__BROWSER__ && resolveSetupReference(`v-${name}`, context)
307+
const fromSetup = resolveSetupReference(`v-${name}`, context)
309308
if (fromSetup) {
310309
name = fromSetup
311310
} else {

packages/compiler-vapor/src/transforms/vBind.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,9 @@ export const transformVBind: DirectiveTransform = (dir, node, context) => {
4040

4141
if (!exp) exp = normalizeBindShorthand(arg, context)
4242
if (!exp.content.trim()) {
43-
if (!__BROWSER__) {
44-
// #10280 only error against empty expression in non-browser build
45-
// because :foo in in-DOM templates will be parsed into :foo="" by the
46-
// browser
47-
context.options.onError(
48-
createCompilerError(ErrorCodes.X_V_BIND_NO_EXPRESSION, loc),
49-
)
50-
}
43+
context.options.onError(
44+
createCompilerError(ErrorCodes.X_V_BIND_NO_EXPRESSION, loc),
45+
)
5146
exp = createSimpleExpression('', true, loc)
5247
}
5348

packages/compiler-vapor/src/transforms/vModel.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ export const transformVModel: DirectiveTransform = (dir, node, context) => {
4646

4747
const expString = exp.content
4848
const maybeRef =
49-
!__BROWSER__ &&
5049
context.options.inline &&
5150
(bindingType === BindingTypes.SETUP_LET ||
5251
bindingType === BindingTypes.SETUP_REF ||

packages/compiler-vapor/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export function resolveExpression(
6060
export function getLiteralExpressionValue(
6161
exp: SimpleExpressionNode,
6262
): number | string | boolean | null {
63-
if (!__BROWSER__ && exp.ast) {
63+
if (exp.ast) {
6464
if (
6565
['StringLiteral', 'NumericLiteral', 'BigIntLiteral'].includes(
6666
exp.ast.type,

0 commit comments

Comments
 (0)