Skip to content

Commit bcca475

Browse files
authored
feat(compiler-core): support accessing Error as global in template expressions (#7018)
1 parent 2a507e3 commit bcca475

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ describe('compiler: expression transform', () => {
161161
type: NodeTypes.COMPOUND_EXPRESSION,
162162
children: [{ content: `Math` }, `.`, { content: `max` }, `(1, 2)`]
163163
})
164+
165+
expect(
166+
(parseWithExpressionTransform(`{{ new Error() }}`) as InterpolationNode)
167+
.content
168+
).toMatchObject({
169+
type: NodeTypes.COMPOUND_EXPRESSION,
170+
children: ['new ', { content: 'Error' }, '()']
171+
})
164172
})
165173

166174
test('should not prefix reserved literals', () => {

packages/shared/src/globalsAllowList.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { makeMap } from './makeMap'
33
const GLOBALS_ALLOWED =
44
'Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,' +
55
'decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,' +
6-
'Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,console'
6+
'Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,console,Error'
77

88
export const isGloballyAllowed = /*#__PURE__*/ makeMap(GLOBALS_ALLOWED)
99

0 commit comments

Comments
 (0)