From 36e81ba9b72508b9c489811e311878cefc2f81bc Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Mon, 5 Nov 2018 11:23:15 -0800 Subject: [PATCH 1/2] Fix shady-unscoped styles and add tests --- CHANGELOG.md | 3 +++ index.js | 3 ++- package.json | 2 +- tests/app/index.html | 19 +++++++++++++++++++ tests/app/shady-unscoped.html | 29 +++++++++++++++++++++++++++++ 5 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 tests/app/shady-unscoped.html diff --git a/CHANGELOG.md b/CHANGELOG.md index 02f3117..0f8296c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Change Log +## Unreleased +- Fix `shady-unscoped` style imports and add tests + ## [0.6.0] - 2018-09-17 * Add support for Polymer v1 `var(--foo, --bar)` => `var(--foo,var(--bar))` transform diff --git a/index.js b/index.js index 50f9a05..7bf2673 100644 --- a/index.js +++ b/index.js @@ -159,6 +159,7 @@ function inlineStyleIncludes(style, useNativeShadow) { includedStyles.forEach((ism) => { // do not inline styles that need to be unscoped in ShadyDOM if (!useNativeShadow && isUnscopedStyle(ism)) { + leftover.push(id); return; } // this style may also have includes @@ -584,7 +585,7 @@ async function polymerCssBuild(paths, options = {}) { consumed.forEach((c) => dom5.remove(c)); dom5.setTextContent(finalStyle, text.join('')); const oldInclude = getAttributeArray(finalStyle, 'include'); - const newInclude = oldInclude.concat(includes).join(' '); + const newInclude = Array.from(new Set(oldInclude.concat(includes))).join(' '); if (newInclude) { dom5.setAttribute(finalStyle, 'include', newInclude); } diff --git a/package.json b/package.json index 5a6b537..199179d 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "rollup": "^0.65.2", "rollup-plugin-node-resolve": "^3.4.0", "wct-browser-legacy": "^1.0.1", - "web-component-tester": "^6.7.1" + "web-component-tester": "^6.9.0" }, "dependencies": { "command-line-args": "^5.0.2", diff --git a/tests/app/index.html b/tests/app/index.html index 3632508..d8256c6 100644 --- a/tests/app/index.html +++ b/tests/app/index.html @@ -20,6 +20,7 @@ + + + + + + + \ No newline at end of file From a595d247a4abb101e08a3e8cc5d6c5fd6a833bf0 Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Mon, 5 Nov 2018 11:56:14 -0800 Subject: [PATCH 2/2] fix transform of test file, only test unscoped dom in shady builds --- tests/app/index.html | 2 +- tests/prepare-tests.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/app/index.html b/tests/app/index.html index d8256c6..44e0623 100644 --- a/tests/app/index.html +++ b/tests/app/index.html @@ -137,7 +137,7 @@ const div = Polymer.dom(root).querySelector('div'); assertComputed(div, '10px'); assertComputed(div, 'rgb(255, 0, 255)', 'background-color'); - if ((Polymer.Settings && !Polymer.Settings.useShadow) || (window.ShadyCSS && !window.ShadyCSS.nativeShadow)) { + if (buildType === 'shady') { const testEl = document.createElement('div'); testEl.setAttribute('unscoped', ''); testEl.classList.add('included'); diff --git a/tests/prepare-tests.sh b/tests/prepare-tests.sh index b660924..a76f3d2 100755 --- a/tests/prepare-tests.sh +++ b/tests/prepare-tests.sh @@ -23,7 +23,7 @@ build(){ cp -rv tests/app/* "tests/${outputDir}/" - bin/polymer-css-build --polymer-version=${version} ${shady} ${noInline} --file tests/${outputDir}/index.html tests/${outputDir}/x-app.html tests/${outputDir}/x-app-dom-module.html tests/${outputDir}/x-app-definition.js tests/${outputDir}/x-component.html tests/${outputDir}/shared/shared-style.html tests/${outputDir}/x-nested-apply.html tests/${outputDir}/cr-bug.html tests/${outputDir}/class-element.js tests/${outputDir}/polymer-1-vars.html + bin/polymer-css-build --polymer-version=${version} ${shady} ${noInline} --file tests/${outputDir}/index.html tests/${outputDir}/x-app.html tests/${outputDir}/x-app-dom-module.html tests/${outputDir}/x-app-definition.js tests/${outputDir}/x-component.html tests/${outputDir}/shared/shared-style.html tests/${outputDir}/x-nested-apply.html tests/${outputDir}/cr-bug.html tests/${outputDir}/class-element.js tests/${outputDir}/polymer-1-vars.html tests/${outputDir}/shady-unscoped.html (cd tests/${outputDir}; npx bower install polymer#${version} web-component-tester) }