'use strict'; const CONSTANTS = require('./constants.js'); const SYNC = 'sync'; const ATTRIBUTE_PRIORITIES = [SYNC, 'async', 'defer']; const common = require('./common.js'); const debug = common.debug; const isScript = common.isScript; const matches = common.matches; const getScriptName = common.getScriptName; const shouldUpdate = (options) => { if (ATTRIBUTE_PRIORITIES.indexOf(options.defaultAttribute) < 0) { throw new Error(`${CONSTANTS.PLUGIN}: invalid default attribute`); } return !(options.defaultAttribute === SYNC && options.inline.test.length === 0 && options.async.test.length === 0 && options.defer.test.length === 0 && options.module.test.length === 0); }; const update = (assets, options, tags) => { const update = updateElement.bind(null, assets, options); return tags.map(update); }; const updateElement = (assets, options, tag) => { return (isScript(tag)) ? updateScriptElement(assets, options, tag) : tag; }; const updateScriptElement = (assets, options, tag) => { debug(`${CONSTANTS.EVENT}: processing