Commit 8297c200 authored by rbpotter's avatar rbpotter Committed by Commit Bot

WebUI Polymer 3: Update polymer script for arrow wrapper functions

Update tools/polymer/polymer.py so that files with content wrapped in:
(() => {
...
})()
are processed the same way as files with content wrapped in:
(function() {
...
})()

Also add a test.

Bug: 965770
Change-Id: I55e7e2bf76e243fbac100ac8e1368fe599df03df
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1775747Reviewed-by: default avatarDan Beam <dbeam@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691800}
parent bd1260c4
......@@ -300,6 +300,7 @@ def _process_dom_module(js_file, html_file):
js_imports = _generate_js_imports(html_file)
IIFE_OPENING = '(function() {\n'
IIFE_OPENING_ARROW = '(() => {\n'
IIFE_CLOSING = '})();'
with open(js_file) as f:
......@@ -310,7 +311,7 @@ def _process_dom_module(js_file, html_file):
for i, line in enumerate(lines):
if not imports_added:
if line.startswith(IIFE_OPENING):
if line.startswith(IIFE_OPENING) or line.startswith(IIFE_OPENING_ARROW):
# Replace the IIFE opening line with the JS imports.
line = '\n'.join(js_imports) + '\n\n'
imports_added = True
......
......@@ -59,6 +59,13 @@ class PolymerModulizerTest(unittest.TestCase):
'dom-module', 'dom_module.html', 'dom_module_iife.js',
'dom_module_iife.m.js', 'dom_module_iife_expected.js')
# Test case where HTML is extracted from a Polymer2 <dom-module> that is
# wrapped in an arrow IIFE function.
def testDomModuleIifeArrow(self):
self._run_test(
'dom-module', 'dom_module.html', 'dom_module_iife_arrow.js',
'dom_module_iife_arrow.m.js', 'dom_module_iife_expected.js')
# Test case where HTML is extracted from a Polymer2 style module.
def testStyleModule(self):
self._run_test(
......
(() => {
const foo = 'foo';
Polymer({
is: 'cr-test-foo',
behaviors: [Polymer.PaperRippleBehavior],
});
})();
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment