This commit is contained in:
Jarred Sumner
2024-06-22 17:40:45 -07:00
committed by GitHub
parent a9e800ad5f
commit bf7b327f68
4 changed files with 42 additions and 1 deletions

View File

@@ -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

View File

@@ -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

View 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`);
});