Skip to content

Commit

Permalink
fix(binding): Resolve 'Bad name' error on tab
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomByte authored and matz3 committed Jan 24, 2025
1 parent 2e733d2 commit 1466abb
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/linter/xmlTemplate/lib/JSTokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
}

while (this.next()) {
if (this.ch === ' ') {
if (this.ch <= ' ') {
this.next();
return name;
}
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/transpiler/xml/XMLViewBindings.view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
}"
/>

<ObjectStatus
visible="{= ${PrdcssrSuccssrSemanticObjTxt} !== '' &amp;&amp; ${PrdcssrSuccssrSemanticActnTxt} !== '' }"
/>

<!-- Correct import and use of required modules -->
<ObjectStatus
core:require="{
Expand Down
10 changes: 10 additions & 0 deletions test/lib/linter/binding/BindingLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,16 @@ test("XML Expression Binding", (t) => {
t.snapshot(linterContext.generateLintResult("/test.js"));
});

test("XML Expression Binding with encoded ampersand", (t) => {
const {bindingLinter, linterContext} = t.context;

bindingLinter.lintPropertyBinding(
"{= ${PrdcssrSuccssrSemanticObjTxt} !== '' && ${PrdcssrSuccssrSemanticActnTxt} !== '' }",
[], {line: 1, column: 1});

t.snapshot(linterContext.generateLintResult("/test.js"));
});

test("Error Testing: XML Property Binding missing closing bracket", (t) => {
const {bindingLinter, linterContext} = t.context;

Expand Down
13 changes: 13 additions & 0 deletions test/lib/linter/binding/snapshots/BindingLinter.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,19 @@ Generated by [AVA](https://avajs.dev).

## XML Expression Binding

> Snapshot 1
{
coverageInfo: [],
errorCount: 0,
fatalErrorCount: 0,
filePath: '/test.js',
messages: [],
warningCount: 0,
}

## XML Expression Binding with encoded ampersand

> Snapshot 1
{
Expand Down
Binary file modified test/lib/linter/binding/snapshots/BindingLinter.ts.snap
Binary file not shown.
18 changes: 18 additions & 0 deletions test/lib/linter/xmlTemplate/lib/JSTokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@ test("JSTokenizer: Basic values", (t) => {
});
});

test("JSTokenizer: Tab after unquoted key", (t) => {
const res = JSTokenizer.parseJS(
`{path\t: 'invoice>Status', formatter: 'ui5.walkthrough.model.formatter.statusText'}`);
t.deepEqual(res, {
path: "invoice>Status",
formatter: "ui5.walkthrough.model.formatter.statusText",
});
});

test("JSTokenizer: Tab after quoted key", (t) => {
const res = JSTokenizer.parseJS(
`{"path"\t: 'invoice>Status', formatter: 'ui5.walkthrough.model.formatter.statusText'}`);
t.deepEqual(res, {
path: "invoice>Status",
formatter: "ui5.walkthrough.model.formatter.statusText",
});
});

test("JSTokenizer: Not allowed", (t) => {
t.throws(() => {
JSTokenizer.parseJS(`{
Expand Down
8 changes: 7 additions & 1 deletion test/lib/linter/xmlTemplate/snapshots/transpiler.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,7 @@ Generated by [AVA](https://avajs.dev).
import ObjectStatus from "sap/m/ObjectStatus";␊
import ObjectStatus2 from "sap/m/ObjectStatus";␊
import ObjectStatus3 from "sap/m/ObjectStatus";␊
import ObjectStatus4 from "sap/m/ObjectStatus";␊
import View from "sap/ui/core/mvc/View";␊
const oObjectStatus = new ObjectStatus({␊
text: "{\\n\\t\\t\\tpath: 'invoice>Status',\\n\\t\\t\\tformatter: 'ui5.walkthrough.model.formatter.statusText',\\n\\t\\t\\tevents: {\\n\\t\\t\\t\\tdataRequested: 'global.onMyDataRequested'\\n\\t\\t\\t}\\n\\t\\t}",␊
Expand All @@ -1347,6 +1348,10 @@ Generated by [AVA](https://avajs.dev).
});␊
const oObjectStatus3 = new ObjectStatus3({␊
visible: "{= ${PrdcssrSuccssrSemanticObjTxt} !== '' && ${PrdcssrSuccssrSemanticActnTxt} !== '' }",␊
});␊
const oObjectStatus4 = new ObjectStatus4({␊
text: "{\\n\\t\\t\\tpath: 'invoice>Status',\\n\\t\\t\\tformatter: 'Formatter.statusText.bind($controller)',\\n\\t\\t\\tevents: {\\n\\t\\t\\t\\tdataRequested: 'EventHandler.onMyDataRequested'\\n\\t\\t\\t}\\n\\t\\t}",␊
customData: "{\\n\\t\\t\\tpath: 'invoice>StatusDetails',\\n\\t\\t\\tfactory: 'Factory',\\n\\t\\t\\tfilters: [{\\n\\t\\t\\t\\ttest: 'FilterTest.testMethod'\\n\\t\\t\\t}, {\\n\\t\\t\\t\\tfilters: [{\\n\\t\\t\\t\\t\\tpath: 'ReturnFlag',\\n\\t\\t\\t\\t\\toperator: 'EQ',\\n\\t\\t\\t\\t\\tvalue1: 'Y'\\n\\t\\t\\t\\t}, {\\n\\t\\t\\t\\t\\ttest: 'FilterTest.testMethod'\\n\\t\\t\\t\\t}]\\n\\t\\t\\t}]\\n\\t\\t}",␊
});␊
Expand All @@ -1357,6 +1362,7 @@ Generated by [AVA](https://avajs.dev).
oObjectStatus,␊
oObjectStatus2,␊
oObjectStatus3,␊
oObjectStatus4,␊
],␊
});␊
Expand All @@ -1366,7 +1372,7 @@ Generated by [AVA](https://avajs.dev).
{
file: 'XMLViewBindings.view.js',
mappings: 'AAkDE,4CAKE;AALF,iCAKE;AALF,uCAKE;AALF,wDAKE;AA9CH,8CA6BE;AAGF,+CAKE;AAGF,+CA6BE;AA9EH,wCAIC;sBAKA,kBA6BE;IA7BY,6LAMX;IAEF,qGAGE;IAEF,wVAcE;IACF,kCAAgC;;;uBAIjC,mBAKE;IAJD,6EAGE;;;uBAIH,mBA6BE;IAtBD,+LAME;IACF,iVAcE;;;6BA7EJ,UAIC;IADA,4CAA0C;IAM1C,OA6BE',
mappings: 'AAsDE,4CAKE;AALF,iCAKE;AALF,uCAKE;AALF,wDAKE;AAlDH,8CA6BE;AAGF,+CAKE;AAEF,+CAEE;AAGF,+CA6BE;AAlFH,wCAIC;sBAKA,kBA6BE;IA7BY,6LAMX;IAEF,qGAGE;IAEF,wVAcE;IACF,kCAAgC;;;uBAIjC,mBAKE;IAJD,6EAGE;;;uBAGH,mBAEE;IADD,kGAAwG;;;uBAIzG,mBA6BE;IAtBD,+LAME;IACF,iVAcE;;;6BAjFJ,UAIC;IADA,4CAA0C;IAM1C,OA6BE',
names: [],
sources: [
'XMLViewBindings.view.xml',
Expand Down
Binary file modified test/lib/linter/xmlTemplate/snapshots/transpiler.ts.snap
Binary file not shown.

0 comments on commit 1466abb

Please sign in to comment.