Skip to content

Commit

Permalink
fix: isIdentifierName should reject empty string (#11339)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Mar 26, 2020
1 parent a901bd5 commit 6a00cbe
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions packages/babel-helper-validator-identifier/test/identifier.spec.js
@@ -0,0 +1,22 @@
import { isIdentifierName } from "..";

describe("isIdentifierName", function() {
it("returns false if provided string is empty", function() {
expect(isIdentifierName("")).toBe(false);
});
it.each(["hello", "$", "ゆゆ式", "$20", "hello20", "_", "if"])(
"returns true if provided string %p is an IdentifierName",
function(word) {
expect(isIdentifierName(word)).toBe(true);
},
);
it.each(["+hello", "0$", "-ゆゆ式", "#_", "_#"])(
"returns false if provided string %p is not an IdentifierName",
function(word) {
expect(isIdentifierName(word)).toBe(false);
},
);
it("supports astral symbols", function() {
expect(isIdentifierName("x\uDB40\uDDD5")).toBe(true);
});
});

0 comments on commit 6a00cbe

Please sign in to comment.