Skip to content

Commit 45bb7f5

Browse files
committed
js-core-1.8.1 monaco-1.2.5 - fix parser detection of aliased functions
1 parent 9d6fc26 commit 45bb7f5

File tree

6 files changed

+23
-21
lines changed

6 files changed

+23
-21
lines changed

javascript/json-transform-core/package-lock.json

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

javascript/json-transform-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@nlighten/json-transform-core",
33
"description": "Core types and utilities for handling JSON transformers",
4-
"version": "1.8.0",
4+
"version": "1.8.1",
55
"main": "./dist/index.js",
66
"source": "src/index.ts",
77
"exports": "./dist/index.js",

javascript/json-transform-core/src/__tests__/functionsParser.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,18 @@ describe("functions schema detection", () => {
5353
"$.a2": NUMBER_ARRAY,
5454
"$.a2[]": NUMBER,
5555
};
56+
const altAlias = `$$${functionsParser.get(funcName).aliases?.[0]}`;
5657
expect(
5758
transformerResult(
5859
{
5960
inline: `${alias}:$.a2`,
61+
inlineAlias: `${altAlias}:$.a2`,
6062
object: {
6163
[alias]: [null, null, "A"],
6264
},
65+
objectAlias: {
66+
[altAlias]: [null, null, "A"],
67+
},
6368
object2: {
6469
[alias]: [null, null, 0.5],
6570
},
@@ -76,15 +81,19 @@ describe("functions schema detection", () => {
7681
additionalProperties: false,
7782
properties: {
7883
inline: NUMBER,
84+
inlineAlias: NUMBER,
7985
object: STRING,
86+
objectAlias: STRING,
8087
object2: NUMBER,
8188
object3: INTEGER,
8289
},
8390
type: "object",
8491
},
8592
...givenTypeMap,
8693
"$.inline": NUMBER,
94+
"$.inlineAlias": NUMBER,
8795
"$.object": STRING,
96+
"$.objectAlias": STRING,
8897
"$.object2": NUMBER,
8998
"$.object3": INTEGER,
9099
},

javascript/json-transform-core/src/functions/functionsParser.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ class FunctionsParser {
6161
* 5 - What comes after the colon (value) -- only when 'noArgs' = false
6262
*/
6363
private inlineFunctionRegexFactory = (names: string[], global: boolean, noArgs: boolean) =>
64-
new RegExp(
65-
`\\$\\$(${Array.from(this.getNames()).join("|")})(\\((.*?)\\))?(:${noArgs ? "" : `([^"]*)`}|$|")`,
66-
global ? "g" : undefined,
67-
);
64+
new RegExp(`\\$\\$(${names.join("|")})(\\((.*?)\\))?(:${noArgs ? "" : `([^"]*)`}|$|")`, global ? "g" : undefined);
6865

6966
private objectFunctionRegexFactory = (names: string[]) => new RegExp(`(?<=")\\$\\$(${names.join("|")})":`, "g");
7067

@@ -125,22 +122,18 @@ class FunctionsParser {
125122

126123
matchInline(
127124
data: any,
128-
callback?: (
129-
funcName: EmbeddedTransformerFunction,
130-
func: FunctionDescriptor,
131-
value: any,
132-
args: Record<string, any>,
133-
) => any,
125+
callback?: (funcName: string, func: FunctionDescriptor, value: any, args: Record<string, any>) => any,
134126
) {
135127
if (typeof data !== "string") return null;
136128

137129
const m = data.match(this.matchInlineFunctionWithArgsRegex);
138130
if (!m) {
139131
return null;
140132
}
141-
const funcName = m[1] as EmbeddedTransformerFunction;
133+
let funcName = m[1];
142134
let func = functionsParser.get(funcName);
143135
if (!func) return null;
136+
if (func.aliasTo) funcName = func.aliasTo;
144137
if (func.subfunctions || callback) {
145138
const argsWithoutParenthesis = m[3];
146139
const args = parseArgs(func, argsWithoutParenthesis);
@@ -165,7 +158,7 @@ class FunctionsParser {
165158
}
166159
const func = getSubfunction(this.get(funcName), data);
167160
return {
168-
name: funcName,
161+
name: func.aliasTo ?? funcName,
169162
func,
170163
value,
171164
spec: data,

javascript/monaco-json-transform/package-lock.json

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

javascript/monaco-json-transform/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nlighten/monaco-json-transform",
3-
"version": "1.2.4",
3+
"version": "1.2.5",
44
"description": "JSON Transform language tokenizer (and syntax highlight), hover provider and more",
55
"main": "./dist/index.js",
66
"source": "src/index.ts",
@@ -42,7 +42,7 @@
4242
"homepage": "https://github.com/nlighten-oss/json-transform#readme",
4343
"peerDependencies": {
4444
"@nlighten/json-schema-utils": "^1.0.3",
45-
"@nlighten/json-transform-core": "^1.7.1",
45+
"@nlighten/json-transform-core": "^1.8.1",
4646
"monaco-editor": "*"
4747
},
4848
"devDependencies": {

0 commit comments

Comments
 (0)