mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
@@ -48,6 +48,7 @@ pub const JumpTable = struct {
|
||||
// explicitly tell LLVM's optimizer about values we know will not be in the range of this switch statement
|
||||
0xaa...0xffd7 => isIdentifierPartSlow16(@as(u16, @intCast(codepoint))),
|
||||
(0xffd7 + 1)...0xe01ef => isIdentifierPartSlow32(codepoint),
|
||||
|
||||
else => false,
|
||||
};
|
||||
}
|
||||
@@ -108,6 +109,8 @@ pub const JumpTable = struct {
|
||||
'A'...'Z', 'a'...'z', '0'...'9', '$', '_' => true,
|
||||
else => if (codepoint < 128)
|
||||
return false
|
||||
else if (codepoint == 0x200C or codepoint == 0x200D)
|
||||
return true
|
||||
else
|
||||
return isIdentifierPartSlow(codepoint),
|
||||
};
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -12919,6 +12919,13 @@ fn NewParser_(
|
||||
}
|
||||
}
|
||||
|
||||
// Handle invalid identifiers in property names
|
||||
// https://github.com/oven-sh/bun/issues/12039
|
||||
if (p.lexer.token == .t_syntax_error) {
|
||||
p.log.addRangeErrorFmt(p.source, name_range, p.allocator, "Unexpected {}", .{bun.fmt.quote(name)}) catch bun.outOfMemory();
|
||||
return error.SyntaxError;
|
||||
}
|
||||
|
||||
key = p.newExpr(E.String{ .data = name }, name_range.loc);
|
||||
|
||||
// Parse a shorthand property
|
||||
|
||||
29
test/regression/issue/012039.test.ts
Normal file
29
test/regression/issue/012039.test.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { test, expect } from "bun:test";
|
||||
|
||||
// Previously, this would crash due to the invalid property name
|
||||
test("#12039 ZWJ", async () => {
|
||||
const code = /*js*/ `
|
||||
export default class {
|
||||
W;
|
||||
}
|
||||
`;
|
||||
expect(() => new Bun.Transpiler().transformSync(code)).not.toThrow();
|
||||
});
|
||||
|
||||
test("#12039 ZWNJ", async () => {
|
||||
const code = /*js*/ `
|
||||
export default class {
|
||||
W${String.fromCodePoint(0x200d)};
|
||||
}
|
||||
`;
|
||||
expect(() => new Bun.Transpiler().transformSync(code)).not.toThrow();
|
||||
});
|
||||
|
||||
test("#12039 invalid property name for identifier", async () => {
|
||||
const code = /*js*/ `
|
||||
export default class {
|
||||
W${String.fromCodePoint(129)};
|
||||
}
|
||||
`;
|
||||
expect(() => new Bun.Transpiler().transformSync(code)).toThrow(`Unexpected "W`);
|
||||
});
|
||||
Reference in New Issue
Block a user