]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat(compiler-core): support accessing Error as global in template expressions (...
authorEduardo San Martin Morote <posva@users.noreply.github.com>
Thu, 30 Nov 2023 08:39:40 +0000 (09:39 +0100)
committerGitHub <noreply@github.com>
Thu, 30 Nov 2023 08:39:40 +0000 (16:39 +0800)
packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts
packages/shared/src/globalsAllowList.ts

index 0d18c1bebe5258f63d3c607451c8f9021f15ae97..a9697930c95dce6d0ce058d598753a3f1fd284d4 100644 (file)
@@ -161,6 +161,14 @@ describe('compiler: expression transform', () => {
       type: NodeTypes.COMPOUND_EXPRESSION,
       children: [{ content: `Math` }, `.`, { content: `max` }, `(1, 2)`]
     })
+
+    expect(
+      (parseWithExpressionTransform(`{{ new Error() }}`) as InterpolationNode)
+        .content
+    ).toMatchObject({
+      type: NodeTypes.COMPOUND_EXPRESSION,
+      children: ['new ', { content: 'Error' }, '()']
+    })
   })
 
   test('should not prefix reserved literals', () => {
index 4af518c22f1138b47ee03e15a37504a81a0b42fa..210650e3e2b01a9eb45878f4927ee1ac32115e23 100644 (file)
@@ -3,7 +3,7 @@ import { makeMap } from './makeMap'
 const GLOBALS_ALLOWED =
   'Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,' +
   'decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,' +
-  'Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,console'
+  'Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,console,Error'
 
 export const isGloballyAllowed = /*#__PURE__*/ makeMap(GLOBALS_ALLOWED)