Skip to content

Commit

Permalink
test coverage for invalid private name usage
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Jun 21, 2020
1 parent b619b02 commit fa3af72
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions scripts/end-to-end-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,37 @@
new Foo().bar()
`,
}),
test(['in.js', '--outfile=node.js', '--target=es6'], {
'in.js': `
function expect(fn, msg) {
try {
fn()
} catch (e) {
if (e instanceof TypeError && e.message === msg) return
}
throw 'expected ' + msg
}
class Foo {
#foo
#method() {}
get #getter() {}
set #setter() {}
bar() {
let obj = {}
expect(() => obj.#foo, 'Cannot read from private field')
expect(() => obj.#foo = 1, 'Cannot write to private field')
expect(() => obj.#getter, 'Cannot read from private field')
expect(() => obj.#setter = 1, 'Cannot write to private field')
expect(() => obj.#method, 'Cannot access private method')
expect(() => obj.#method = 1, 'Cannot write to private field')
expect(() => this.#setter, 'member.get is not a function')
expect(() => this.#getter = 1, 'member.set is not a function')
expect(() => this.#method = 1, 'member.set is not a function')
}
}
new Foo().bar()
`,
}),
)

// Async lowering tests
Expand Down

0 comments on commit fa3af72

Please sign in to comment.