diff options
author | 2022-03-04 00:26:13 -0800 | |
---|---|---|
committer | 2022-03-04 00:26:13 -0800 | |
commit | d8d5b1a071db82edcf36b1abc3f72158c7967ce8 (patch) | |
tree | 1a8ad50c51f50ecbd023ccd78271e6c0cae2e8a5 /integration/bunjs-only-snippets/transpiler.test.js | |
parent | bb64920cf0dda9d53f0f4e0918fb7af1c7acebb4 (diff) | |
download | bun-d8d5b1a071db82edcf36b1abc3f72158c7967ce8.tar.gz bun-d8d5b1a071db82edcf36b1abc3f72158c7967ce8.tar.zst bun-d8d5b1a071db82edcf36b1abc3f72158c7967ce8.zip |
more tests
Diffstat (limited to 'integration/bunjs-only-snippets/transpiler.test.js')
-rw-r--r-- | integration/bunjs-only-snippets/transpiler.test.js | 68 |
1 files changed, 61 insertions, 7 deletions
diff --git a/integration/bunjs-only-snippets/transpiler.test.js b/integration/bunjs-only-snippets/transpiler.test.js index 8dfb8f9d4..2859c2b02 100644 --- a/integration/bunjs-only-snippets/transpiler.test.js +++ b/integration/bunjs-only-snippets/transpiler.test.js @@ -47,6 +47,65 @@ describe("Bun.Transpiler", () => { `; + it("require with a dynamic non-string expression", () => { + var nodeTranspiler = new Bun.Transpiler({ platform: "node" }); + expect(nodeTranspiler.transformSync("require('hi' + bar)")).toBe( + 'require("hi" + bar);\n' + ); + }); + + it("CommonJS", () => { + var nodeTranspiler = new Bun.Transpiler({ platform: "node" }); + expect(nodeTranspiler.transformSync("module.require('hi' + 123)")).toBe( + 'require("hi" + 123);\n' + ); + + expect( + nodeTranspiler.transformSync("module.require(1 ? 'foo' : 'bar')") + ).toBe('require("foo");\n'); + expect(nodeTranspiler.transformSync("require(1 ? 'foo' : 'bar')")).toBe( + 'require("foo");\n' + ); + + expect( + nodeTranspiler.transformSync("module.require(unknown ? 'foo' : 'bar')") + ).toBe('unknown ? require("foo") : require("bar");\n'); + }); + + describe("regressions", () => { + it("unexpected super", () => { + const input = ` + 'use strict'; + + const ErrorReportingMixinBase = require('./mixin-base'); + const PositionTrackingPreprocessorMixin = require('../position-tracking/preprocessor-mixin'); + const Mixin = require('../../utils/mixin'); + + class ErrorReportingPreprocessorMixin extends ErrorReportingMixinBase { + constructor(preprocessor, opts) { + super(preprocessor, opts); + + this.posTracker = Mixin.install(preprocessor, PositionTrackingPreprocessorMixin); + this.lastErrOffset = -1; + } + + _reportError(code) { + //NOTE: avoid reporting error twice on advance/retreat + if (this.lastErrOffset !== this.posTracker.offset) { + this.lastErrOffset = this.posTracker.offset; + super._reportError(code); + } + } + } + + module.exports = ErrorReportingPreprocessorMixin; + + +`; + expect(transpiler.transformSync(input, "js").length > 0).toBe(true); + }); + }); + describe("scanImports", () => { it("reports import paths, excluding types", () => { const imports = transpiler.scanImports(code, "tsx"); @@ -395,11 +454,7 @@ describe("Bun.Transpiler", () => { "(({}) = {}) => {}", "Unexpected parentheses in binding pattern" ); - expectParseError( - "function f(([]) = []) {}", - "Parse error" - // 'Expected identifier but found "("\n' - ); + expectParseError("function f(([]) = []) {}", "Parse error"); expectParseError( "function f(({}) = {}) {}", "Parse error" @@ -516,8 +571,7 @@ describe("Bun.Transpiler", () => { ); expectParseError( "class Foo extends Bar { #foo; foo() { super.#foo } }", - "Parse error" - // 'Expected identifier but found "#foo"' + 'Expected identifier but found "#foo"' ); expectParseError( "class Foo { #foo = () => { for (#foo in this) ; } }", |