Skip to content

Commit

Permalink
fix: incorrect error message for browser UMD bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
harttle committed Jun 4, 2023
1 parent fc42438 commit 3a67eb7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/util/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@ export abstract class LiquidError extends Error {
public context = ''
private originalError?: Error
public constructor (err: Error | string, token: Token) {
/**
* note: for ES5 targeting, `this` will be replaced by return value of Error(),
* thus everything on `this` will be lost, avoid calling `LiquidError` methods here
*/
super(typeof err === 'string' ? err : err.message)
if (typeof err !== 'string') this.defineUnEnumerable('originalError', err)
this.defineUnEnumerable('token', token)
}
private defineUnEnumerable (property: string, value: unknown) {
Object.defineProperty(this, property, {
value: value,
enumerable: false
})
if (typeof err !== 'string') Object.defineProperty(this, 'originalError', { value: err, enumerable: false })
Object.defineProperty(this, 'token', { value: token, enumerable: false })
}
protected update () {
this.defineUnEnumerable('context', mkContext(this.token))
Object.defineProperty(this, 'context', { value: mkContext(this.token), enumerable: false })
this.message = mkMessage(this.message, this.token)
this.stack = this.message + '\n' + this.context +
'\n' + this.stack
Expand Down
10 changes: 10 additions & 0 deletions test/e2e/browser.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const LiquidUMD = require('../../dist/liquid.browser.umd.js').Liquid

describe('browser', function () {
it('should yield unclosed output error', () => {
const engine = new LiquidUMD()
return expect(engine.parseAndRender('{{huh')).rejects.toMatchObject({
message: 'output "{{huh" not closed, line:1, col:1'
})
})
})

0 comments on commit 3a67eb7

Please sign in to comment.