diff --git a/.github/renovate.json5 b/.github/renovate.json5 index 08fd191e1..82b193a81 100644 --- a/.github/renovate.json5 +++ b/.github/renovate.json5 @@ -52,7 +52,7 @@ ], }, { - groupName: "Angular Estree", + groupName: "Angular Estree parser", matchPackageNames: ["@angular/compiler", "angular-estree-parser"], }, { diff --git a/package.json b/package.json index 5721eebef..ae4dd6009 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "bin" ], "dependencies": { - "@angular/compiler": "21.0.7", + "@angular/compiler": "21.0.8", "@babel/code-frame": "8.0.0-beta.3", "@babel/parser": "8.0.0-beta.3", "@babel/types": "8.0.0-beta.3", @@ -55,7 +55,7 @@ "@typescript-eslint/visitor-keys": "8.52.0", "acorn": "8.15.0", "acorn-jsx": "5.3.2", - "angular-estree-parser": "15.0.0", + "angular-estree-parser": "15.1.3", "angular-html-parser": "10.2.1", "camelcase": "9.0.0", "ci-info": "4.3.1", diff --git a/src/language-js/parse/angular.js b/src/language-js/parse/angular.js index abc4c9139..7781d12b7 100644 --- a/src/language-js/parse/angular.js +++ b/src/language-js/parse/angular.js @@ -4,23 +4,56 @@ import { parseInterpolationExpression, parseTemplateBindings, } from "angular-estree-parser"; +import createError from "../../common/parser-create-error.js"; import { locEnd, locStart } from "../loc.js"; +function createParseError(error) { + /* c8 ignore next 3 */ + if (!error?.location) { + return error; + } + + const { + message, + location: { line, col: column }, + } = error; + + return createError(message, { + loc: { + start: { line: line + 1, column }, + }, + cause: error, + }); +} + /** - * @param {parseAction | parseBinding | parseInterpolationExpression | parseTemplateBindings} parseMethod - */ +@typedef {parseAction | parseBinding | parseInterpolationExpression | parseTemplateBindings} Parsers +*/ + +/** +@template {Parsers} ParseMethod +@param {ParseMethod} parseMethod +*/ function createParser(parseMethod) { return { astFormat: "estree", parse(text) { - let node = parseMethod(text); + /** @type {ReturnType} */ + let node; + + try { + // @ts-expect-error -- safe + node = parseMethod(text); + } catch (error) { + throw createParseError(error); + } + // @ts-expect-error -- safe const { comments } = node; // @ts-expect-error -- safe delete node.comments; if (parseMethod === parseAction && node.type !== "NGChainedExpression") { - // @ts-expect-error -- expected node = { ...node, type: "NGChainedExpression", expressions: [node] }; } diff --git a/tests/format/misc/errors/front-matter/__snapshots__/format.test.js.snap b/tests/format/misc/errors/front-matter/__snapshots__/format.test.js.snap index 142573f75..2804e7a0b 100644 --- a/tests/format/misc/errors/front-matter/__snapshots__/format.test.js.snap +++ b/tests/format/misc/errors/front-matter/__snapshots__/format.test.js.snap @@ -18,19 +18,62 @@ exports[`snippet: Should not support front matter [__js_expression] format 1`] = Cause: Unexpected parseExpression() input: The input should contain exactly one expression, but the first expression is followed by the unexpected character \`M\`. (2:6)" `; -exports[`snippet: Should not support front matter [__ng_action] format 1`] = `"Unexpected token 'Matter'"`; +exports[`snippet: Should not support front matter [__ng_action] format 1`] = ` +"Parser Error: Unexpected token 'Matter' (2:7) + 1 | --- +> 2 | Front Matter content + | ^ + 3 | --- +Cause: Parser Error: Unexpected token 'Matter' +Cause: Parser Error: Unexpected token 'Matter' at column 11 in [--- +Front Matter content +---] in test.html@0:0" +`; -exports[`snippet: Should not support front matter [__ng_binding] format 1`] = `"Unexpected token 'Matter'"`; +exports[`snippet: Should not support front matter [__ng_binding] format 1`] = ` +"Parser Error: Unexpected token 'Matter' (2:7) + 1 | --- +> 2 | Front Matter content + | ^ + 3 | --- +Cause: Parser Error: Unexpected token 'Matter' +Cause: Parser Error: Unexpected token 'Matter' at column 11 in [--- +Front Matter content +---] in test.html@0:0" +`; exports[`snippet: Should not support front matter [__ng_directive] format 1`] = ` -"Unexpected end of expression: --- +"Parser Error: Unexpected end of expression: --- +Front Matter content +--- at the end of the expression [--- +Front Matter content +---] (1:0) +> 1 | --- + 2 | Front Matter content + 3 | --- +Cause: Parser Error: Unexpected end of expression: --- +Front Matter content +--- at the end of the expression [--- +Front Matter content +---] +Cause: Parser Error: Unexpected end of expression: --- Front Matter content --- at the end of the expression [--- Front Matter content ---] in test.html@0:0" `; -exports[`snippet: Should not support front matter [__ng_interpolation] format 1`] = `"Unexpected token 'Matter'"`; +exports[`snippet: Should not support front matter [__ng_interpolation] format 1`] = ` +"Parser Error: Unexpected token 'Matter' (2:7) + 1 | --- +> 2 | Front Matter content + | ^ + 3 | --- +Cause: Parser Error: Unexpected token 'Matter' +Cause: Parser Error: Unexpected token 'Matter' at column 11 in [--- +Front Matter content +---] in test.html@0:0" +`; exports[`snippet: Should not support front matter [__ts_expression] format 1`] = ` "The input should contain exactly one expression, but the first expression is followed by the unexpected character \`M\`. (2:7) diff --git a/yarn.lock b/yarn.lock index 2efd970ce..8079fbfdc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5,12 +5,12 @@ __metadata: version: 8 cacheKey: 10 -"@angular/compiler@npm:21.0.7": - version: 21.0.7 - resolution: "@angular/compiler@npm:21.0.7" +"@angular/compiler@npm:21.0.8": + version: 21.0.8 + resolution: "@angular/compiler@npm:21.0.8" dependencies: tslib: "npm:^2.3.0" - checksum: 10/ce950aeda8f6d0a3930e296fef1645d945003094039bc5b763631ed043905396611ef655ac3b0b3b32d1c4b01d86577c354aca7d69ca6ce5ff51bbb6886a3610 + checksum: 10/966788d3ec3a413d5be1ad478d0f302bef8675429b7be7c6a8bacc4d9386f2030ca00bfd98dc6bda8ad4ab9403440d5d8f9b613745d7a5660c64b27aac4e71c4 languageName: node linkType: hard @@ -2883,12 +2883,12 @@ __metadata: languageName: node linkType: hard -"angular-estree-parser@npm:15.0.0": - version: 15.0.0 - resolution: "angular-estree-parser@npm:15.0.0" +"angular-estree-parser@npm:15.1.3": + version: 15.1.3 + resolution: "angular-estree-parser@npm:15.1.3" peerDependencies: "@angular/compiler": ">=21.0.7" - checksum: 10/d099ae3976fdbc0bb4a42785363319a05398c7982c2ee2efb107e8cad0ddd8fc2cf2ed642368b9c39a2eba8e39380db2903420eab18bcae9a05b3423e341b759 + checksum: 10/4b64a552e65660225c223734eea5c1f1105ba00a3ad3f1f3dfdf3f7b1743f9161650ccee1695d2d5953ffdd0dcd09c2e42ba5b2f140e430548aaeccfc1834bdb languageName: node linkType: hard @@ -8359,7 +8359,7 @@ __metadata: version: 0.0.0-use.local resolution: "prettier@workspace:." dependencies: - "@angular/compiler": "npm:21.0.7" + "@angular/compiler": "npm:21.0.8" "@babel/code-frame": "npm:8.0.0-beta.3" "@babel/generator": "npm:8.0.0-beta.3" "@babel/parser": "npm:8.0.0-beta.3" @@ -8378,7 +8378,7 @@ __metadata: "@typescript-eslint/visitor-keys": "npm:8.52.0" acorn: "npm:8.15.0" acorn-jsx: "npm:5.3.2" - angular-estree-parser: "npm:15.0.0" + angular-estree-parser: "npm:15.1.3" angular-html-parser: "npm:10.2.1" base64-arraybuffer-es6: "npm:3.1.0" browserslist: "npm:4.28.1"