From 0378b2f85b1761988db4c24af6e48b3e6cc18a77 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Wed, 10 Apr 2024 15:39:34 -0700 Subject: [PATCH] chore(template-compiler): update acorn and fix its types --- packages/@lwc/template-compiler/package.json | 3 +-- .../template-compiler/src/typings/acorn.d.ts | 16 ++++++++++++++++ yarn.lock | 7 +------ 3 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 packages/@lwc/template-compiler/src/typings/acorn.d.ts diff --git a/packages/@lwc/template-compiler/package.json b/packages/@lwc/template-compiler/package.json index 43a6dbcb25..1e5c40e036 100644 --- a/packages/@lwc/template-compiler/package.json +++ b/packages/@lwc/template-compiler/package.json @@ -42,10 +42,9 @@ } }, "dependencies": { - "//": "Acorn is pinned due to a breaking change in its types in 8.11: https://github.com/acornjs/acorn/issues/1260", "@lwc/errors": "6.5.0", "@lwc/shared": "6.5.0", - "acorn": "8.10.0", + "acorn": "~8.11.3", "astring": "~1.8.6", "estree-walker": "~2.0.2", "he": "~1.2.0" diff --git a/packages/@lwc/template-compiler/src/typings/acorn.d.ts b/packages/@lwc/template-compiler/src/typings/acorn.d.ts new file mode 100644 index 0000000000..600f9f66f7 --- /dev/null +++ b/packages/@lwc/template-compiler/src/typings/acorn.d.ts @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024, Salesforce, Inc. + * All rights reserved. + * SPDX-License-Identifier: MIT + * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT + */ + +import type { Expression, Options } from 'acorn'; + +// Acorn shipped a breaking change in its types: https://github.com/acornjs/acorn/issues/1260 +// This is a workaround based on Svelte's solution: https://github.com/sveltejs/svelte/pull/10301 +declare module 'acorn' { + export function isIdentifierStart(code: number, astral?: boolean): boolean; + export function isIdentifierChar(code: number, astral?: boolean): boolean; + export function parseExpressionAt(input: string, pos: number, options: Options): Expression; +} diff --git a/yarn.lock b/yarn.lock index d2d27c4a0a..fb723d044a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2599,12 +2599,7 @@ acorn-walk@^8.0.2: resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.3.2.tgz#7703af9415f1b6db9315d6895503862e231d34aa" integrity sha512-cjkyv4OtNCIeqhHrfS81QWXoCBPExR/J62oyEqepVw8WaQeSqpW2uhuLPh1m9eWhDuOo/jUXVTlifvesOWp/4A== -acorn@8.10.0: - version "8.10.0" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.10.0.tgz#8be5b3907a67221a81ab23c7889c4c5526b62ec5" - integrity sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw== - -acorn@^8.1.0, acorn@^8.8.1, acorn@^8.8.2, acorn@^8.9.0: +acorn@^8.1.0, acorn@^8.8.1, acorn@^8.8.2, acorn@^8.9.0, acorn@~8.11.3: version "8.11.3" resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.11.3.tgz#71e0b14e13a4ec160724b38fb7b0f233b1b81d7a" integrity sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==