From b2e3a73e2ff406778a65415747391df6bf85a2ce Mon Sep 17 00:00:00 2001 From: kpdecker Date: Sun, 19 Jul 2015 10:39:38 +0300 Subject: [PATCH] Use generic name for templateObject Rather than using variable names that could be quite long, just use indexed generic names that use runtime lookup for the string parameter mapping. --- packages/babel/src/transformation/file/index.js | 2 +- .../es6.template-literals/tag-loose/actual.js | 2 +- .../es6.template-literals/tag-loose/expected.js | 8 ++++++-- .../transformation/es6.template-literals/tag/expected.js | 8 ++------ 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/babel/src/transformation/file/index.js b/packages/babel/src/transformation/file/index.js index 7a81feb583..1253224892 100644 --- a/packages/babel/src/transformation/file/index.js +++ b/packages/babel/src/transformation/file/index.js @@ -418,7 +418,7 @@ export default class File { var declar = this.declarations[name]; if (declar) return declar; - var uid = this.declarations[name] = this.scope.generateUidIdentifier(name); + var uid = this.declarations[name] = this.scope.generateUidIdentifier("templateObject"); var helperId = this.addHelper(helperName); var init = t.callExpression(helperId, [strings, raw]); diff --git a/packages/babel/test/fixtures/transformation/es6.template-literals/tag-loose/actual.js b/packages/babel/test/fixtures/transformation/es6.template-literals/tag-loose/actual.js index cfa5638dbd..52419bb505 100644 --- a/packages/babel/test/fixtures/transformation/es6.template-literals/tag-loose/actual.js +++ b/packages/babel/test/fixtures/transformation/es6.template-literals/tag-loose/actual.js @@ -1,3 +1,3 @@ var foo = bar`wow\na${ 42 }b ${_.foobar()}`; var bar = bar`wow\nab${ 42 } ${_.foobar()}`; -var bar = bar`wow\naB${ 42 } ${_.foobar()}`; +var bar = bar`wow\naB${ 42 } ${_.baz()}`; diff --git a/packages/babel/test/fixtures/transformation/es6.template-literals/tag-loose/expected.js b/packages/babel/test/fixtures/transformation/es6.template-literals/tag-loose/expected.js index 3665e56ad2..9378680632 100644 --- a/packages/babel/test/fixtures/transformation/es6.template-literals/tag-loose/expected.js +++ b/packages/babel/test/fixtures/transformation/es6.template-literals/tag-loose/expected.js @@ -1,7 +1,11 @@ "use strict"; -var _taggedTemplateLiteralLoose_3_wowNaB = _taggedTemplateLiteralLoose(["wow\na", "b ", ""], ["wow\\na", "b ", ""]); +var _templateObject = _taggedTemplateLiteralLoose(["wow\na", "b ", ""], ["wow\\na", "b ", ""]), + _templateObject2 = _taggedTemplateLiteralLoose(["wow\nab", " ", ""], ["wow\\nab", " ", ""]), + _templateObject3 = _taggedTemplateLiteralLoose(["wow\naB", " ", ""], ["wow\\naB", " ", ""]); function _taggedTemplateLiteralLoose(strings, raw) { strings.raw = raw; return strings; } -var foo = bar(_taggedTemplateLiteralLoose_3_wowNaB, 42, _.foobar()); \ No newline at end of file +var foo = bar(_templateObject, 42, _.foobar()); +var bar = bar(_templateObject2, 42, _.foobar()); +var bar = bar(_templateObject3, 42, _.baz()); \ No newline at end of file diff --git a/packages/babel/test/fixtures/transformation/es6.template-literals/tag/expected.js b/packages/babel/test/fixtures/transformation/es6.template-literals/tag/expected.js index 1a4289dd50..7749db566b 100644 --- a/packages/babel/test/fixtures/transformation/es6.template-literals/tag/expected.js +++ b/packages/babel/test/fixtures/transformation/es6.template-literals/tag/expected.js @@ -1,11 +1,7 @@ "use strict"; -var _taggedTemplateLiteral_3_wowNaB = _taggedTemplateLiteral(["wow\na", "b ", ""], ["wow\\na", "b ", ""]), - _taggedTemplateLiteral_3_wowNab = _taggedTemplateLiteral(["wow\nab", " ", ""], ["wow\\nab", " ", ""]), - _taggedTemplateLiteral_3_wowNaB2 = _taggedTemplateLiteral(["wow\naB", " ", ""], ["wow\\naB", " ", ""]); +var _templateObject = _taggedTemplateLiteral(["wow\na", "b ", ""], ["wow\\na", "b ", ""]); function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); } -var foo = bar(_taggedTemplateLiteral_3_wowNaB, 42, _.foobar()); -var bar = bar(_taggedTemplateLiteral_3_wowNab, 42, _.foobar()); -var bar = bar(_taggedTemplateLiteral_3_wowNaB2, 42, _.foobar()); \ No newline at end of file +var foo = bar(_templateObject, 42, _.foobar());