@vue/compiler-vapor 3.6.0-alpha.6 → 3.6.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compiler-vapor.cjs.js +150 -39
- package/dist/compiler-vapor.esm-browser.js +2464 -266
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vue/compiler-vapor v3.6.0-
|
|
2
|
+
* @vue/compiler-vapor v3.6.0-beta.1
|
|
3
3
|
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
@@ -370,10 +370,10 @@ const IMPORT_EXPR_RE = new RegExp(
|
|
|
370
370
|
`${IMPORT_EXP_START}(.*?)${IMPORT_EXP_END}`,
|
|
371
371
|
"g"
|
|
372
372
|
);
|
|
373
|
-
const NEWLINE = Symbol(`newline` );
|
|
374
|
-
const LF = Symbol(`line feed` );
|
|
375
|
-
const INDENT_START = Symbol(`indent start` );
|
|
376
|
-
const INDENT_END = Symbol(`indent end` );
|
|
373
|
+
const NEWLINE = /* @__PURE__ */ Symbol(`newline` );
|
|
374
|
+
const LF = /* @__PURE__ */ Symbol(`line feed` );
|
|
375
|
+
const INDENT_START = /* @__PURE__ */ Symbol(`indent start` );
|
|
376
|
+
const INDENT_END = /* @__PURE__ */ Symbol(`indent end` );
|
|
377
377
|
function buildCodeFragment(...frag) {
|
|
378
378
|
const push = frag.push.bind(frag);
|
|
379
379
|
const unshift = frag.unshift.bind(frag);
|
|
@@ -1084,7 +1084,7 @@ function genSetDynamicEvents(oper, context) {
|
|
|
1084
1084
|
)
|
|
1085
1085
|
];
|
|
1086
1086
|
}
|
|
1087
|
-
function genEventHandler(context, values, modifiers = { nonKeys: [], keys: [] }, extraWrap = false) {
|
|
1087
|
+
function genEventHandler(context, values, modifiers = { nonKeys: [], keys: [] }, asComponentProp = false, extraWrap = false) {
|
|
1088
1088
|
let handlerExp = [];
|
|
1089
1089
|
if (values) {
|
|
1090
1090
|
values.forEach((value, index) => {
|
|
@@ -1092,7 +1092,7 @@ function genEventHandler(context, values, modifiers = { nonKeys: [], keys: [] },
|
|
|
1092
1092
|
if (value && value.content.trim()) {
|
|
1093
1093
|
if (compilerDom.isMemberExpression(value, context.options)) {
|
|
1094
1094
|
exp = genExpression(value, context);
|
|
1095
|
-
if (!isConstantBinding(value, context) && !
|
|
1095
|
+
if (!isConstantBinding(value, context) && !asComponentProp) {
|
|
1096
1096
|
const isTSNode = value.ast && compilerDom.TS_NODE_TYPES.includes(value.ast.type);
|
|
1097
1097
|
exp = [
|
|
1098
1098
|
`e => `,
|
|
@@ -1622,7 +1622,7 @@ function genPropKey({ key: node, modifier, runtimeCamelize, handler, handlerModi
|
|
|
1622
1622
|
const { helper } = context;
|
|
1623
1623
|
const handlerModifierPostfix = handlerModifiers && handlerModifiers.options ? handlerModifiers.options.map(shared.capitalize).join("") : "";
|
|
1624
1624
|
if (node.isStatic) {
|
|
1625
|
-
const keyName = (handler ? shared.toHandlerKey(node.content) : node.content) + handlerModifierPostfix;
|
|
1625
|
+
const keyName = (handler ? shared.toHandlerKey(shared.camelize(node.content)) : node.content) + handlerModifierPostfix;
|
|
1626
1626
|
return [
|
|
1627
1627
|
[
|
|
1628
1628
|
compilerDom.isSimpleIdentifier(keyName) ? keyName : JSON.stringify(keyName),
|
|
@@ -1875,7 +1875,7 @@ function genCreateComponent(operation, context) {
|
|
|
1875
1875
|
const rawProps = context.withId(() => genRawProps(props, context), ids);
|
|
1876
1876
|
const inlineHandlers = handlers.reduce(
|
|
1877
1877
|
(acc, { name, value }) => {
|
|
1878
|
-
const handler = genEventHandler(context, [value], void 0, false);
|
|
1878
|
+
const handler = genEventHandler(context, [value], void 0, false, false);
|
|
1879
1879
|
return [...acc, `const ${name} = `, ...handler, NEWLINE];
|
|
1880
1880
|
},
|
|
1881
1881
|
[]
|
|
@@ -1969,7 +1969,89 @@ function genRawProps(props, context) {
|
|
|
1969
1969
|
}
|
|
1970
1970
|
}
|
|
1971
1971
|
function genStaticProps(props, context, dynamicProps) {
|
|
1972
|
-
const args =
|
|
1972
|
+
const args = [];
|
|
1973
|
+
const handlerGroups = /* @__PURE__ */ new Map();
|
|
1974
|
+
const ensureHandlerGroup = (keyName, keyFrag) => {
|
|
1975
|
+
let group = handlerGroups.get(keyName);
|
|
1976
|
+
if (!group) {
|
|
1977
|
+
const index = args.length;
|
|
1978
|
+
args.push([]);
|
|
1979
|
+
group = { keyFrag, handlers: [], index };
|
|
1980
|
+
handlerGroups.set(keyName, group);
|
|
1981
|
+
}
|
|
1982
|
+
return group;
|
|
1983
|
+
};
|
|
1984
|
+
const addHandler = (keyName, keyFrag, handlerExp) => {
|
|
1985
|
+
ensureHandlerGroup(keyName, keyFrag).handlers.push(handlerExp);
|
|
1986
|
+
};
|
|
1987
|
+
const getStaticPropKeyName = (prop) => {
|
|
1988
|
+
if (!prop.key.isStatic) return;
|
|
1989
|
+
const handlerModifierPostfix = prop.handlerModifiers && prop.handlerModifiers.options ? prop.handlerModifiers.options.map((m) => m.charAt(0).toUpperCase() + m.slice(1)).join("") : "";
|
|
1990
|
+
const keyName = (prop.handler ? shared.toHandlerKey(shared.camelize(prop.key.content)) : prop.key.content) + handlerModifierPostfix;
|
|
1991
|
+
return keyName;
|
|
1992
|
+
};
|
|
1993
|
+
for (const prop of props) {
|
|
1994
|
+
if (prop.handler) {
|
|
1995
|
+
const keyName = getStaticPropKeyName(prop);
|
|
1996
|
+
if (!keyName) {
|
|
1997
|
+
args.push(genProp(prop, context, true));
|
|
1998
|
+
continue;
|
|
1999
|
+
}
|
|
2000
|
+
const keyFrag = genPropKey(prop, context);
|
|
2001
|
+
const hasModifiers = !!prop.handlerModifiers && (prop.handlerModifiers.keys.length > 0 || prop.handlerModifiers.nonKeys.length > 0);
|
|
2002
|
+
if (hasModifiers || prop.values.length <= 1) {
|
|
2003
|
+
const handlerExp = genEventHandler(
|
|
2004
|
+
context,
|
|
2005
|
+
prop.values,
|
|
2006
|
+
prop.handlerModifiers,
|
|
2007
|
+
true,
|
|
2008
|
+
false
|
|
2009
|
+
);
|
|
2010
|
+
addHandler(keyName, keyFrag, handlerExp);
|
|
2011
|
+
} else {
|
|
2012
|
+
for (const value of prop.values) {
|
|
2013
|
+
const handlerExp = genEventHandler(
|
|
2014
|
+
context,
|
|
2015
|
+
[value],
|
|
2016
|
+
prop.handlerModifiers,
|
|
2017
|
+
true,
|
|
2018
|
+
false
|
|
2019
|
+
);
|
|
2020
|
+
addHandler(keyName, keyFrag, handlerExp);
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
continue;
|
|
2024
|
+
}
|
|
2025
|
+
args.push(genProp(prop, context, true));
|
|
2026
|
+
if (prop.model) {
|
|
2027
|
+
if (prop.key.isStatic) {
|
|
2028
|
+
const keyName = `onUpdate:${shared.camelize(prop.key.content)}`;
|
|
2029
|
+
const keyFrag = [JSON.stringify(keyName)];
|
|
2030
|
+
addHandler(keyName, keyFrag, genModelHandler(prop.values[0], context));
|
|
2031
|
+
} else {
|
|
2032
|
+
const keyFrag = [
|
|
2033
|
+
'["onUpdate:" + ',
|
|
2034
|
+
...genExpression(prop.key, context),
|
|
2035
|
+
"]"
|
|
2036
|
+
];
|
|
2037
|
+
args.push([
|
|
2038
|
+
...keyFrag,
|
|
2039
|
+
": () => ",
|
|
2040
|
+
...genModelHandler(prop.values[0], context)
|
|
2041
|
+
]);
|
|
2042
|
+
}
|
|
2043
|
+
const { key, modelModifiers } = prop;
|
|
2044
|
+
if (modelModifiers && modelModifiers.length) {
|
|
2045
|
+
const modifiersKey = key.isStatic ? [shared.getModifierPropName(key.content)] : ["[", ...genExpression(key, context), ' + "Modifiers"]'];
|
|
2046
|
+
const modifiersVal = genDirectiveModifiers(modelModifiers);
|
|
2047
|
+
args.push([...modifiersKey, `: () => ({ ${modifiersVal} })`]);
|
|
2048
|
+
}
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
for (const group of handlerGroups.values()) {
|
|
2052
|
+
const handlerValue = group.handlers.length > 1 ? genMulti(DELIMITERS_ARRAY_NEWLINE, ...group.handlers) : group.handlers[0];
|
|
2053
|
+
args[group.index] = [...group.keyFrag, ": () => ", ...handlerValue];
|
|
2054
|
+
}
|
|
1973
2055
|
if (dynamicProps) {
|
|
1974
2056
|
args.push([`$: `, ...dynamicProps]);
|
|
1975
2057
|
}
|
|
@@ -1989,11 +2071,46 @@ function genDynamicProps(props, context) {
|
|
|
1989
2071
|
}
|
|
1990
2072
|
continue;
|
|
1991
2073
|
} else {
|
|
1992
|
-
if (p.kind === 1)
|
|
1993
|
-
|
|
1994
|
-
|
|
2074
|
+
if (p.kind === 1) {
|
|
2075
|
+
if (p.model) {
|
|
2076
|
+
const entries = [genProp(p, context)];
|
|
2077
|
+
const updateKey = p.key.isStatic ? [
|
|
2078
|
+
JSON.stringify(`onUpdate:${shared.camelize(p.key.content)}`)
|
|
2079
|
+
] : [
|
|
2080
|
+
'["onUpdate:" + ',
|
|
2081
|
+
...genExpression(p.key, context),
|
|
2082
|
+
"]"
|
|
2083
|
+
];
|
|
2084
|
+
entries.push([
|
|
2085
|
+
...updateKey,
|
|
2086
|
+
": () => ",
|
|
2087
|
+
...genModelHandler(p.values[0], context)
|
|
2088
|
+
]);
|
|
2089
|
+
const { modelModifiers } = p;
|
|
2090
|
+
if (modelModifiers && modelModifiers.length) {
|
|
2091
|
+
const modifiersKey = p.key.isStatic ? [shared.getModifierPropName(p.key.content)] : [
|
|
2092
|
+
"[",
|
|
2093
|
+
...genExpression(p.key, context),
|
|
2094
|
+
' + "Modifiers"]'
|
|
2095
|
+
];
|
|
2096
|
+
const modifiersVal = genDirectiveModifiers(modelModifiers);
|
|
2097
|
+
entries.push([...modifiersKey, `: () => ({ ${modifiersVal} })`]);
|
|
2098
|
+
}
|
|
2099
|
+
expr = genMulti(DELIMITERS_OBJECT_NEWLINE, ...entries);
|
|
2100
|
+
} else {
|
|
2101
|
+
expr = genMulti(DELIMITERS_OBJECT, genProp(p, context));
|
|
2102
|
+
}
|
|
2103
|
+
} else {
|
|
1995
2104
|
expr = genExpression(p.value, context);
|
|
1996
|
-
if (p.handler)
|
|
2105
|
+
if (p.handler)
|
|
2106
|
+
expr = genCall(
|
|
2107
|
+
helper("toHandlers"),
|
|
2108
|
+
expr,
|
|
2109
|
+
`false`,
|
|
2110
|
+
// preserveCaseIfNecessary: false, not needed for component
|
|
2111
|
+
`true`
|
|
2112
|
+
// wrap handler values in functions
|
|
2113
|
+
);
|
|
1997
2114
|
}
|
|
1998
2115
|
}
|
|
1999
2116
|
frags.push(["() => (", ...expr, ")"]);
|
|
@@ -2011,23 +2128,11 @@ function genProp(prop, context, isStatic) {
|
|
|
2011
2128
|
context,
|
|
2012
2129
|
prop.values,
|
|
2013
2130
|
prop.handlerModifiers,
|
|
2131
|
+
true,
|
|
2014
2132
|
true
|
|
2015
|
-
) : isStatic ? ["() => (", ...values, ")"] : values
|
|
2016
|
-
...prop.model ? [...genModelEvent(prop, context), ...genModelModifiers(prop, context)] : []
|
|
2133
|
+
) : isStatic ? ["() => (", ...values, ")"] : values
|
|
2017
2134
|
];
|
|
2018
2135
|
}
|
|
2019
|
-
function genModelEvent(prop, context) {
|
|
2020
|
-
const name = prop.key.isStatic ? [JSON.stringify(`onUpdate:${shared.camelize(prop.key.content)}`)] : ['["onUpdate:" + ', ...genExpression(prop.key, context), "]"];
|
|
2021
|
-
const handler = genModelHandler(prop.values[0], context);
|
|
2022
|
-
return [",", NEWLINE, ...name, ": () => ", ...handler];
|
|
2023
|
-
}
|
|
2024
|
-
function genModelModifiers(prop, context) {
|
|
2025
|
-
const { key, modelModifiers } = prop;
|
|
2026
|
-
if (!modelModifiers || !modelModifiers.length) return [];
|
|
2027
|
-
const modifiersKey = key.isStatic ? [shared.getModifierPropName(key.content)] : ["[", ...genExpression(key, context), ' + "Modifiers"]'];
|
|
2028
|
-
const modifiersVal = genDirectiveModifiers(modelModifiers);
|
|
2029
|
-
return [",", NEWLINE, ...modifiersKey, `: () => ({ ${modifiersVal} })`];
|
|
2030
|
-
}
|
|
2031
2136
|
function genRawSlots(slots, context) {
|
|
2032
2137
|
if (!slots.length) return;
|
|
2033
2138
|
const staticSlots = slots[0];
|
|
@@ -2466,7 +2571,13 @@ function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`) {
|
|
|
2466
2571
|
}
|
|
2467
2572
|
} else {
|
|
2468
2573
|
if (elementIndex === 0) {
|
|
2469
|
-
pushBlock(
|
|
2574
|
+
pushBlock(
|
|
2575
|
+
...genCall(
|
|
2576
|
+
helper("child"),
|
|
2577
|
+
from,
|
|
2578
|
+
logicalIndex !== 0 ? String(logicalIndex) : void 0
|
|
2579
|
+
)
|
|
2580
|
+
);
|
|
2470
2581
|
} else {
|
|
2471
2582
|
let init = genCall(helper("child"), from);
|
|
2472
2583
|
if (elementIndex === 1) {
|
|
@@ -3193,13 +3304,13 @@ const transformVHtml = (dir, node, context) => {
|
|
|
3193
3304
|
let { exp, loc } = dir;
|
|
3194
3305
|
if (!exp) {
|
|
3195
3306
|
context.options.onError(
|
|
3196
|
-
compilerDom.createDOMCompilerError(
|
|
3307
|
+
compilerDom.createDOMCompilerError(54, loc)
|
|
3197
3308
|
);
|
|
3198
3309
|
exp = EMPTY_EXPRESSION;
|
|
3199
3310
|
}
|
|
3200
3311
|
if (node.children.length) {
|
|
3201
3312
|
context.options.onError(
|
|
3202
|
-
compilerDom.createDOMCompilerError(
|
|
3313
|
+
compilerDom.createDOMCompilerError(55, loc)
|
|
3203
3314
|
);
|
|
3204
3315
|
context.childrenTemplate.length = 0;
|
|
3205
3316
|
}
|
|
@@ -3225,13 +3336,13 @@ const transformVText = (dir, node, context) => {
|
|
|
3225
3336
|
let { exp, loc } = dir;
|
|
3226
3337
|
if (!exp) {
|
|
3227
3338
|
context.options.onError(
|
|
3228
|
-
compilerDom.createDOMCompilerError(
|
|
3339
|
+
compilerDom.createDOMCompilerError(56, loc)
|
|
3229
3340
|
);
|
|
3230
3341
|
exp = EMPTY_EXPRESSION;
|
|
3231
3342
|
}
|
|
3232
3343
|
if (node.children.length) {
|
|
3233
3344
|
context.options.onError(
|
|
3234
|
-
compilerDom.createDOMCompilerError(
|
|
3345
|
+
compilerDom.createDOMCompilerError(57, loc)
|
|
3235
3346
|
);
|
|
3236
3347
|
context.childrenTemplate.length = 0;
|
|
3237
3348
|
}
|
|
@@ -3264,7 +3375,7 @@ function normalizeBindShorthand(arg, context) {
|
|
|
3264
3375
|
if (arg.type !== 4 || !arg.isStatic) {
|
|
3265
3376
|
context.options.onError(
|
|
3266
3377
|
compilerDom.createCompilerError(
|
|
3267
|
-
|
|
3378
|
+
53,
|
|
3268
3379
|
arg.loc
|
|
3269
3380
|
)
|
|
3270
3381
|
);
|
|
@@ -3381,7 +3492,7 @@ const transformVShow = (dir, node, context) => {
|
|
|
3381
3492
|
const { exp, loc } = dir;
|
|
3382
3493
|
if (!exp) {
|
|
3383
3494
|
context.options.onError(
|
|
3384
|
-
compilerDom.createDOMCompilerError(
|
|
3495
|
+
compilerDom.createDOMCompilerError(62, loc)
|
|
3385
3496
|
);
|
|
3386
3497
|
return;
|
|
3387
3498
|
}
|
|
@@ -3580,7 +3691,7 @@ const transformVModel = (dir, node, context) => {
|
|
|
3580
3691
|
if (dir.arg)
|
|
3581
3692
|
context.options.onError(
|
|
3582
3693
|
compilerDom.createDOMCompilerError(
|
|
3583
|
-
|
|
3694
|
+
59,
|
|
3584
3695
|
dir.arg.loc
|
|
3585
3696
|
)
|
|
3586
3697
|
);
|
|
@@ -3605,7 +3716,7 @@ const transformVModel = (dir, node, context) => {
|
|
|
3605
3716
|
modelType = void 0;
|
|
3606
3717
|
context.options.onError(
|
|
3607
3718
|
compilerDom.createDOMCompilerError(
|
|
3608
|
-
|
|
3719
|
+
60,
|
|
3609
3720
|
dir.loc
|
|
3610
3721
|
)
|
|
3611
3722
|
);
|
|
@@ -3628,7 +3739,7 @@ const transformVModel = (dir, node, context) => {
|
|
|
3628
3739
|
} else {
|
|
3629
3740
|
context.options.onError(
|
|
3630
3741
|
compilerDom.createDOMCompilerError(
|
|
3631
|
-
|
|
3742
|
+
58,
|
|
3632
3743
|
dir.loc
|
|
3633
3744
|
)
|
|
3634
3745
|
);
|
|
@@ -3647,7 +3758,7 @@ const transformVModel = (dir, node, context) => {
|
|
|
3647
3758
|
if (value && compilerDom.isStaticArgOf(value.arg, "value")) {
|
|
3648
3759
|
context.options.onError(
|
|
3649
3760
|
compilerDom.createDOMCompilerError(
|
|
3650
|
-
|
|
3761
|
+
61,
|
|
3651
3762
|
value.loc
|
|
3652
3763
|
)
|
|
3653
3764
|
);
|