From 4176c6c28314c547d1f2184afc728e5f2c4d704c Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Fri, 14 Jul 2017 16:58:54 -0700 Subject: [PATCH] cleanup and update npm dependencies --- externs/webcomponents-externs.js | 3 -- gulpfile.js | 8 +++--- package.json | 7 +++-- util/minimalDocument.js | 48 +++++++++----------------------- 4 files changed, 21 insertions(+), 45 deletions(-) diff --git a/externs/webcomponents-externs.js b/externs/webcomponents-externs.js index d483b83c0c..d06dc892ee 100644 --- a/externs/webcomponents-externs.js +++ b/externs/webcomponents-externs.js @@ -39,9 +39,6 @@ let ShadyDOM = { window.ShadyDOM = ShadyDOM; -/** @type {function(this:ShadowRoot)} */ -ShadowRoot.prototype.forceRender; - let WebComponents = {}; window.WebComponents = WebComponents; diff --git a/gulpfile.js b/gulpfile.js index c39ce3d95f..744efaf108 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -25,6 +25,7 @@ const lazypipe = require('lazypipe'); const closure = require('google-closure-compiler').gulp(); const minimalDocument = require('./util/minimalDocument.js') const dom5 = require('dom5'); +const parse5 = require('parse5'); const DIST_DIR = 'dist'; const BUNDLED_DIR = path.join(DIST_DIR, 'bundled'); @@ -76,7 +77,7 @@ class AddClosureTypeImport extends Transform { _transform(file, enc, cb) { if (file.path === this.target) { let contents = file.contents.toString(); - let html = dom5.parse(contents, {locationInfo: true}); + let html = parse5.parse(contents, {locationInfo: true}); let firstImport = dom5.query(html, firstImportFinder); if (firstImport) { let importPath = path.relative(path.dirname(this.target), this.importPath); @@ -84,7 +85,8 @@ class AddClosureTypeImport extends Transform { dom5.setAttribute(importLink, 'rel', 'import'); dom5.setAttribute(importLink, 'href', importPath); dom5.insertBefore(firstImport.parentNode, firstImport, importLink); - file.contents = Buffer(dom5.serialize(html)); + dom5.removeFakeRootElements(html); + file.contents = Buffer(parse5.serialize(html)); } } cb(null, file); @@ -105,7 +107,6 @@ gulp.task('closure', ['clean'], () => { } config('polymer.html'); - // config('lib/mixins/property-effects.html'); const project = new PolymerProject({ shell: `./${entry}`, @@ -146,7 +147,6 @@ gulp.task('closure', ['clean'], () => { new_type_inf: true, checks_only: CLOSURE_LINT_ONLY, polymer_version: 2, - // tracer_mode: 'TIMING_ONLY', externs: [ 'bower_components/shadycss/externs/shadycss-externs.js', 'externs/webcomponents-externs.js', diff --git a/package.json b/package.json index bcb96f3fab..1a49d3c9c8 100644 --- a/package.json +++ b/package.json @@ -13,9 +13,9 @@ "@webcomponents/webcomponentsjs": "^1.0.0", "babel-preset-babili": "^0.1.4", "del": "^3.0.0", - "dom5": "^1.3.1", + "dom5": "^2.3.0", "eslint-plugin-html": "^2.0.1", - "google-closure-compiler": "^20170521.0.0", + "google-closure-compiler": "^20170626.0.0", "gulp": "^3.9.1", "gulp-babel": "^6.1.2", "gulp-eslint": "^3.0.1", @@ -24,7 +24,8 @@ "gulp-vulcanize": "^6.0.1", "lazypipe": "^1.0.1", "merge-stream": "^1.0.1", - "polymer-build": "^1.5.0", + "parse5": "^3.0.2", + "polymer-build": "^1.6.0", "run-sequence": "^1.1.0", "through2": "^2.0.0", "web-component-tester": "^6.0.0-prerelease.4" diff --git a/util/minimalDocument.js b/util/minimalDocument.js index 17d819497d..7a9fbcf80f 100644 --- a/util/minimalDocument.js +++ b/util/minimalDocument.js @@ -12,34 +12,11 @@ 'use strict'; const dom5 = require('dom5'); +const parse5 = require('parse5'); const {Transform} = require('stream'); const p = dom5.predicates; -function isBlankTextNode(node) { - return node && dom5.isTextNode(node) && !/\S/.test(dom5.getTextContent(node)); -} - -function replaceWithChildren(node) { - if (!node) { - return; - } - let parent = node.parentNode; - let idx = parent.childNodes.indexOf(node); - let children = node.childNodes; - children.forEach(function(n) { - n.parentNode = parent; - }); - let til = idx + 1; - let next = parent.childNodes[til]; - // remove newline text node as well - while (isBlankTextNode(next)) { - til++; - next = parent.childNodes[til]; - } - parent.childNodes = parent.childNodes.slice(0, idx).concat(children, parent.childNodes.slice(til)); -} - function onlyOneLicense(doc) { let comments = dom5.nodeWalkAll(doc, dom5.isCommentNode); let hasLicense = false; @@ -54,24 +31,24 @@ function onlyOneLicense(doc) { } } +const blankRx = /^\s+$/; + +const isBlankNode = p.AND(dom5.isTextNode, (t) => blankRx.test(dom5.getTextContent(t))); + class MinimalDocTransform extends Transform { constructor() { super({objectMode: true}); } _transform(file, enc, cb) { - let doc = dom5.parse(String(file.contents)); - let head = dom5.query(doc, p.hasTagName('head')); - let body = dom5.query(doc, p.hasTagName('body')); - let vulc = dom5.query(body, p.AND(p.hasTagName('div'), p.hasAttr('by-polymer-bundler'), p.hasAttr('hidden'))); + let doc = parse5.parse(String(file.contents), {locationInfo: true}); + let vulc = dom5.query(doc, p.AND(p.hasTagName('div'), p.hasAttr('by-polymer-bundler'), p.hasAttr('hidden'))); let charset = dom5.query(doc, p.AND(p.hasTagName('meta'), p.hasAttrValue('charset', 'UTF-8'))); if (charset) { dom5.remove(charset); } - replaceWithChildren(head); - replaceWithChildren(vulc); - replaceWithChildren(body); + dom5.removeNodeSaveChildren(vulc); let scripts = dom5.queryAll(doc, p.hasTagName('script')); let collector = scripts[0]; @@ -83,12 +60,13 @@ class MinimalDocTransform extends Transform { } dom5.setTextContent(collector, contents.join('')); - let html = dom5.query(doc, p.hasTagName('html')); - replaceWithChildren(html); - onlyOneLicense(doc); - file.contents = new Buffer(dom5.serialize(doc)); + dom5.removeFakeRootElements(doc); + + dom5.nodeWalkAll(doc, isBlankNode).forEach((t) => dom5.remove(t)); + + file.contents = new Buffer(parse5.serialize(doc)); cb(null, file); }