Skip to content

Commit

Permalink
Transform local bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell committed May 19, 2020
1 parent d353b5b commit 390e213
Show file tree
Hide file tree
Showing 21 changed files with 44 additions and 16 deletions.
14 changes: 11 additions & 3 deletions packages/babel-plugin-transform-unicode-escapes/src/index.js
Expand Up @@ -46,7 +46,9 @@ export default declare(api => {
Identifier(path) {
const { node, key } = path;
const { name } = node;
const replaced = name.replace(surrogate, escape);
const replaced = name.replace(surrogate, c => {
return `_u${c.charCodeAt(0).toString(16)}`;
});
if (name === replaced) return;

const str = t.inherits(t.stringLiteral(name), node);
Expand All @@ -56,7 +58,7 @@ export default declare(api => {
return;
}

const { parentPath } = path;
const { parentPath, scope } = path;
if (
parentPath.isMemberExpression({ property: node }) ||
parentPath.isOptionalMemberExpression({ property: node })
Expand All @@ -66,8 +68,14 @@ export default declare(api => {
return;
}

const binding = scope.getBinding(name);
if (binding) {
scope.rename(name, scope.generateUid(replaced));
return;
}

throw path.buildCodeFrameError(
`Can't represent '${name}' as a bare identifier`,
`Can't reference '${name}' as a bare identifier`,
);
},

Expand Down
@@ -0,0 +1 @@
\u{1d49c};
@@ -0,0 +1,3 @@
{
"throws": "Can't reference '𝒜' as a bare identifier"
}
@@ -1 +1,2 @@
var \u{1d49c} = 1;
\u{1d49c};

This file was deleted.

@@ -0,0 +1,2 @@
var _ud835_udc9c = 1;
_ud835_udc9c;
@@ -0,0 +1 @@
var o = { \u{1d49c} };
@@ -0,0 +1,3 @@
{
"throws": "Can't reference '𝒜' as a bare identifier"
}
@@ -1 +1,2 @@
var \u{1d49c} = 1;
var o = { \u{1d49c} };

This file was deleted.

@@ -0,0 +1,4 @@
var _ud835_udc9c = 1;
var o = {
"\uD835\uDC9C": _ud835_udc9c
};
@@ -0,0 +1 @@
𝒜;
@@ -0,0 +1,3 @@
{
"throws": "Can't reference '𝒜' as a bare identifier"
}
@@ -1 +1,2 @@
𝒜 ;
var 𝒜 = 1;
𝒜;

This file was deleted.

@@ -0,0 +1,2 @@
var _ud835_udc9c = 1;
_ud835_udc9c;
@@ -0,0 +1 @@
var o = { 𝒜 };
@@ -0,0 +1,3 @@
{
"throws": "Can't reference '𝒜' as a bare identifier"
}
@@ -1 +1,2 @@
var 𝒜 = 1;
var o = { 𝒜 };

This file was deleted.

@@ -0,0 +1,4 @@
var _ud835_udc9c = 1;
var o = {
"\uD835\uDC9C": _ud835_udc9c
};

0 comments on commit 390e213

Please sign in to comment.