coralite 0.38.5 → 0.38.6
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-setup.d.ts","sourceRoot":"","sources":["../../lib/component-setup.js"],"names":[],"mappings":"AAWA;;;;;GAKG;AAEH;;;;;;GAMG;AACH,mDAHG;IAAuC,GAAG,EAAlC,gBAAgB;CACxB,
|
|
1
|
+
{"version":3,"file":"component-setup.d.ts","sourceRoot":"","sources":["../../lib/component-setup.js"],"names":[],"mappings":"AAWA;;;;;GAKG;AAEH;;;;;;GAMG;AACH,mDAHG;IAAuC,GAAG,EAAlC,gBAAgB;CACxB,YA+MF;AA2ID;;;;;;;;;;;GAWG;AACH,mGAPG;IAAqB,SAAS,EAAtB,GAAG;IACe,QAAQ;IACb,aAAa,EAA1B,GAAG;IACe,aAAa;IACf,IAAI,EAApB,MAAM;CACd,GAAU,OAAO,CAAC,IAAI,CAAC,CAwCzB;sCApZS,mBAAmB"}
|
package/dist/lib/index.js
CHANGED
|
@@ -2300,7 +2300,7 @@ function findAndExtractScript(code) {
|
|
|
2300
2300
|
}
|
|
2301
2301
|
return result;
|
|
2302
2302
|
}
|
|
2303
|
-
function
|
|
2303
|
+
function extractComponentProperty(code, propertyName) {
|
|
2304
2304
|
const ast = getAST(code, true);
|
|
2305
2305
|
let result = null;
|
|
2306
2306
|
walkJS(ast, {
|
|
@@ -2308,11 +2308,11 @@ function findAndExtractProperties(code) {
|
|
|
2308
2308
|
if (node.callee && node.callee.type === "Identifier" && node.callee.name === "defineComponent") {
|
|
2309
2309
|
const firstArg = node.arguments[0];
|
|
2310
2310
|
if (firstArg && firstArg.type === "ObjectExpression") {
|
|
2311
|
-
const
|
|
2312
|
-
(
|
|
2311
|
+
const prop = firstArg.properties.find(
|
|
2312
|
+
(p) => p.type === "Property" && p.key && p.key.type === "Identifier" && p.key.name === propertyName
|
|
2313
2313
|
);
|
|
2314
|
-
if (
|
|
2315
|
-
const { value, method } =
|
|
2314
|
+
if (prop && prop.type === "Property") {
|
|
2315
|
+
const { value, method } = prop;
|
|
2316
2316
|
let startLine = value.loc.start.line - 1;
|
|
2317
2317
|
let prefix = "";
|
|
2318
2318
|
let content = "";
|
|
@@ -2323,15 +2323,22 @@ function findAndExtractProperties(code) {
|
|
|
2323
2323
|
} else if (value.type === "FunctionExpression") {
|
|
2324
2324
|
if (method) {
|
|
2325
2325
|
const isAsync = value.async;
|
|
2326
|
-
prefix += (isAsync ? "async " : "") + "function
|
|
2326
|
+
prefix += (isAsync ? "async " : "") + "function " + propertyName;
|
|
2327
2327
|
content = prefix + source;
|
|
2328
|
-
startLine =
|
|
2328
|
+
startLine = prop.key.loc.start.line - 1;
|
|
2329
2329
|
} else {
|
|
2330
2330
|
content = prefix + source;
|
|
2331
2331
|
startLine = value.loc.start.line - 1;
|
|
2332
2332
|
}
|
|
2333
2333
|
} else if (value.type === "ObjectExpression") {
|
|
2334
|
-
|
|
2334
|
+
if (propertyName === "server") {
|
|
2335
|
+
content = `() => (${source})`;
|
|
2336
|
+
} else {
|
|
2337
|
+
content = source;
|
|
2338
|
+
}
|
|
2339
|
+
startLine = value.loc.start.line - 1;
|
|
2340
|
+
} else if (value.type === "Literal" || value.type === "Identifier") {
|
|
2341
|
+
content = source;
|
|
2335
2342
|
startLine = value.loc.start.line - 1;
|
|
2336
2343
|
}
|
|
2337
2344
|
result = {
|
|
@@ -2750,7 +2757,11 @@ ScriptManager.prototype.compileAllInstances = async function(instances, mode) {
|
|
|
2750
2757
|
const defaults = serialize(normalizedDefaults);
|
|
2751
2758
|
const attributes = serialize(sharedFn.script?.attributes || {});
|
|
2752
2759
|
const hydrationMap = serialize(generateHydrationMap(sharedFn.templateAST, sharedFn.templateValues));
|
|
2753
|
-
|
|
2760
|
+
let normalizedGetters = sharedFn.getters || sharedFn.script?.getters || {};
|
|
2761
|
+
if (normalizedGetters) {
|
|
2762
|
+
normalizedGetters = normalizeObjectFunctions(normalizedGetters, astTransformer);
|
|
2763
|
+
}
|
|
2764
|
+
const getters = serialize(normalizedGetters);
|
|
2754
2765
|
const dependencies = JSON.stringify(sharedFn.components || []);
|
|
2755
2766
|
let normalizedSlots = sharedFn.slots || {};
|
|
2756
2767
|
if (sharedFn.slots) {
|
|
@@ -4067,8 +4078,9 @@ function createComponentDefinition({ app }) {
|
|
|
4067
4078
|
const serializableAttributes = {};
|
|
4068
4079
|
if (attributes) {
|
|
4069
4080
|
for (const [key, schema] of Object.entries(attributes)) {
|
|
4081
|
+
const type = schema.type || schema;
|
|
4070
4082
|
serializableAttributes[key] = {
|
|
4071
|
-
type:
|
|
4083
|
+
type: type.name || type,
|
|
4072
4084
|
default: schema.default
|
|
4073
4085
|
};
|
|
4074
4086
|
}
|
|
@@ -4090,7 +4102,8 @@ function createComponentDefinition({ app }) {
|
|
|
4090
4102
|
};
|
|
4091
4103
|
if (attributes) {
|
|
4092
4104
|
for (const [key, schema] of Object.entries(attributes)) {
|
|
4093
|
-
const
|
|
4105
|
+
const type = schema.type || schema;
|
|
4106
|
+
const typeName = type.name || type;
|
|
4094
4107
|
if (state[key] !== void 0) {
|
|
4095
4108
|
const value = state[key];
|
|
4096
4109
|
if (typeName === "Number") {
|
|
@@ -4260,13 +4273,51 @@ async function _safeRegister(component, scriptManager, scriptResultMeta = null)
|
|
|
4260
4273
|
extractedComponents = extractedClient.components || [];
|
|
4261
4274
|
}
|
|
4262
4275
|
if (!component._extractedServer) {
|
|
4263
|
-
component._extractedServer =
|
|
4276
|
+
component._extractedServer = extractComponentProperty(component.script, "server");
|
|
4264
4277
|
}
|
|
4265
4278
|
const extractedServer = component._extractedServer;
|
|
4266
4279
|
if (extractedServer) {
|
|
4267
4280
|
scriptObj.stateContent = extractedServer.content;
|
|
4268
4281
|
scriptObj.stateLineOffset = (component.lineOffset || 0) + extractedServer.lineOffset;
|
|
4269
4282
|
}
|
|
4283
|
+
if (!scriptResultMeta) {
|
|
4284
|
+
const extractedGetters = extractComponentProperty(component.script, "getters");
|
|
4285
|
+
if (extractedGetters) {
|
|
4286
|
+
try {
|
|
4287
|
+
if (extractedGetters.content.trim().startsWith("{")) {
|
|
4288
|
+
scriptObj.getters = new Function(`return ${extractedGetters.content}`)();
|
|
4289
|
+
}
|
|
4290
|
+
} catch {
|
|
4291
|
+
}
|
|
4292
|
+
}
|
|
4293
|
+
const extractedAttributes = extractComponentProperty(component.script, "attributes");
|
|
4294
|
+
if (extractedAttributes) {
|
|
4295
|
+
try {
|
|
4296
|
+
if (extractedAttributes.content.trim().startsWith("{")) {
|
|
4297
|
+
const attrs = new Function(`return ${extractedAttributes.content}`)();
|
|
4298
|
+
const serializableAttributes = {};
|
|
4299
|
+
for (const [key, schema] of Object.entries(attrs)) {
|
|
4300
|
+
const type = schema.type || schema;
|
|
4301
|
+
serializableAttributes[key] = {
|
|
4302
|
+
type: type.name || type,
|
|
4303
|
+
default: schema.default
|
|
4304
|
+
};
|
|
4305
|
+
}
|
|
4306
|
+
scriptObj.attributes = serializableAttributes;
|
|
4307
|
+
}
|
|
4308
|
+
} catch {
|
|
4309
|
+
}
|
|
4310
|
+
}
|
|
4311
|
+
const extractedSlots = extractComponentProperty(component.script, "slots");
|
|
4312
|
+
if (extractedSlots) {
|
|
4313
|
+
try {
|
|
4314
|
+
if (extractedSlots.content.trim().startsWith("{")) {
|
|
4315
|
+
scriptObj.slots = new Function(`return ${extractedSlots.content}`)();
|
|
4316
|
+
}
|
|
4317
|
+
} catch {
|
|
4318
|
+
}
|
|
4319
|
+
}
|
|
4320
|
+
}
|
|
4270
4321
|
}
|
|
4271
4322
|
const declarativeComponents = (component.customElements || []).map((el) => el.name);
|
|
4272
4323
|
const nestedComponents = [.../* @__PURE__ */ new Set([...declarativeComponents, ...extractedComponents])];
|
|
@@ -5286,7 +5337,7 @@ function createRenderer({
|
|
|
5286
5337
|
extractedComponents = extractedScript.components || [];
|
|
5287
5338
|
}
|
|
5288
5339
|
if (!moduleComponent.result._extractedProperties) {
|
|
5289
|
-
moduleComponent.result._extractedProperties =
|
|
5340
|
+
moduleComponent.result._extractedProperties = extractComponentProperty(module.script, "server");
|
|
5290
5341
|
}
|
|
5291
5342
|
const extractedProperties = moduleComponent.result._extractedProperties;
|
|
5292
5343
|
if (extractedProperties) {
|
|
@@ -6782,9 +6833,9 @@ export {
|
|
|
6782
6833
|
definePlugin,
|
|
6783
6834
|
discoverHtmlFiles,
|
|
6784
6835
|
enhanceNode,
|
|
6836
|
+
extractComponentProperty,
|
|
6785
6837
|
extractGlobals,
|
|
6786
6838
|
findAndExtractImperativeComponents,
|
|
6787
|
-
findAndExtractProperties,
|
|
6788
6839
|
findAndExtractScript,
|
|
6789
6840
|
findHeadAndBody,
|
|
6790
6841
|
generateHydrationMap,
|