Skip to content

Commit 3d8c0dd

Browse files
committed
feat: refactor shared code and update deps
1 parent 4df6996 commit 3d8c0dd

File tree

9 files changed

+47
-33
lines changed

9 files changed

+47
-33
lines changed

inspect-extension/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"version": "0.3.0",
55
"description": "debug for mpx vscode extension",
66
"devDependencies": {
7-
"@mpxjs/core": "2.10.6",
7+
"@mpxjs/core": "catalog:",
88
"typescript": "^5.8.3",
99
"unocss": "^66.2.3",
1010
"vue": "^2.7.0"

packages/language-core/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
"@mpxjs/language-shared": "workspace:*",
2525
"@volar/language-core": "catalog:",
2626
"@vue/compiler-dom": "catalog:",
27-
"@vue/compiler-vue2": "^2.7.16",
28-
"@vue/shared": "catalog:",
2927
"alien-signals": "^1.0.3",
3028
"enhanced-resolve": "^5.18.1",
3129
"minimatch": "^9.0.3",

packages/language-core/src/codegen/template/interpolation.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import type * as ts from 'typescript'
22
import type { TemplateCodegenContext } from './context'
33
import type { Code, MpxCodeInformation, MpxCompilerOptions } from '../../types'
4-
5-
import { isGloballyAllowed, makeMap } from '@vue/shared'
4+
import { isGloballyAllowed, makeMap } from '@mpxjs/language-shared'
65
import { collectVars, createTsAst, identifierRegex } from '../utils'
76
import { getNodeText, getStartEnd } from '../../utils/shared'
87

98
const isLiteralWhitelisted = /*@__PURE__*/ makeMap('true,false,null,this')
10-
11-
// Mpx 支持编译注入的全局声明变量
12-
export const builtInVars = ['__mpx_mode__', '__mpx_env__']
9+
const isMpxGloballyWhitelisted = /*@__PURE__*/ makeMap(
10+
'__mpx_mode__,__mpx_env__',
11+
)
1312

1413
export function* generateInterpolation(
1514
options: {
@@ -187,8 +186,7 @@ function* generateVar(
187186

188187
if (ctx.dollarVars.has(curVar.text)) {
189188
yield [`__MPX_dollars.`, undefined]
190-
}
191-
if (!builtInVars.includes(curVar.text)) {
189+
} else {
192190
yield [`__MPX_ctx.`, undefined]
193191
}
194192
yield [
@@ -323,6 +321,7 @@ function shouldIdentifierSkipped(
323321
return (
324322
ctx.hasLocalVariable(text) ||
325323
isGloballyAllowed(text) ||
324+
isMpxGloballyWhitelisted(text) ||
326325
isLiteralWhitelisted(text) ||
327326
text === 'require' ||
328327
text.startsWith('__VLS_') ||

packages/language-core/src/utils/processJsonBlock.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import { SFCDescriptor, SFCJsonBlock, SFCScriptBlock } from '@vue/compiler-sfc'
21
import type * as ts from 'typescript'
2+
import type {
3+
SFCDescriptor,
4+
SFCJsonBlock,
5+
SFCScriptBlock,
6+
} from '@vue/compiler-sfc'
37

48
export interface ProcessJsonBlockOptions {
59
uri?: string
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { makeMap } from './makeMap'
2+
3+
const GLOBALS_ALLOWED =
4+
'Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,' +
5+
'decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,' +
6+
'Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,console,Error,Symbol'
7+
8+
export const isGloballyAllowed: (key: string) => boolean =
9+
/*@__PURE__*/ makeMap(GLOBALS_ALLOWED)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
export * from './camelize'
2+
export * from './globalsAllowList'
3+
export * from './makeMap'
24
export * from './memoize'
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*! #__NO_SIDE_EFFECTS__ */
2+
export function makeMap(str: string): (key: string) => boolean {
3+
const map = Object.create(null)
4+
for (const key of str.split(',')) map[key] = 1
5+
return val => val in map
6+
}

pnpm-lock.yaml

Lines changed: 18 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ catalog:
1111
'@volar/typescript': ~2.4.12
1212
'@volar/vscode': ~2.4.12
1313
'@vue/compiler-dom': ^3.5.0
14-
'@vue/shared': ^3.5.0
1514
'@types/node': ^22.15.32
1615
'@types/path-browserify': ^1.0.1
1716
'@types/semver': ^7.7.0

0 commit comments

Comments
 (0)