@reearth/core 0.0.7-alpha.60 → 0.0.7-alpha.62

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.
@@ -14,6 +14,7 @@ export function replaceVariables(expression: string, feature?: any): [string, JP
14
14
  const featureDefined = typeof feature !== "undefined";
15
15
  const jsonPathCache: Record<string, any[]> = {};
16
16
  const varExpRegex = /^\$./;
17
+ const quotedStringRegex = /^(["'])(.+)\1$/;
17
18
  while (i >= 0) {
18
19
  if (isInsideQuotes(exp, i)) {
19
20
  const closeQuote = findCloseQuote(exp, i);
@@ -24,7 +25,22 @@ export function replaceVariables(expression: string, feature?: any): [string, JP
24
25
  result += exp.slice(0, i);
25
26
  const j = getCloseBracketIndex(exp, i);
26
27
  const varExp = exp.slice(i + 2, j);
27
- if (varExpRegex.test(varExp)) {
28
+ const quotedMatch = varExp.match(quotedStringRegex);
29
+ if (quotedMatch) {
30
+ // Handle quoted property names like ${"user info"}
31
+ if (!featureDefined) {
32
+ return [result, []];
33
+ }
34
+ const propertyName = quotedMatch[2];
35
+ const propertyValue = feature[propertyName];
36
+ // Return empty string for missing properties to match regular variable behavior
37
+ const placeholderLiteral = generateRandomString(10);
38
+ literalJP.push({
39
+ literalName: placeholderLiteral,
40
+ literalValue: typeof propertyValue !== "undefined" ? propertyValue : "",
41
+ });
42
+ result += placeholderLiteral;
43
+ } else if (varExpRegex.test(varExp)) {
28
44
  if (!featureDefined) {
29
45
  return [result, []];
30
46
  }
@@ -37,16 +53,13 @@ export function replaceVariables(expression: string, feature?: any): [string, JP
37
53
  return [result, []];
38
54
  }
39
55
  }
40
- if (res.length !== 0) {
41
- const placeholderLiteral = generateRandomString(10);
42
- literalJP.push({
43
- literalName: placeholderLiteral,
44
- literalValue: res[0],
45
- });
46
- result += placeholderLiteral;
47
- } else {
48
- return ["false", []];
49
- }
56
+ // Return empty string for missing properties to match regular variable behavior
57
+ const placeholderLiteral = generateRandomString(10);
58
+ literalJP.push({
59
+ literalName: placeholderLiteral,
60
+ literalValue: res.length !== 0 ? res[0] : "",
61
+ });
62
+ result += placeholderLiteral;
50
63
  } else {
51
64
  const replacedVarExp = replaceReservedWord(varExp);
52
65
  result += `${VARIABLE_PREFIX}${replacedVarExp}`;