From be69f8f344dca375211ec28cbbd25b5267fa0899 Mon Sep 17 00:00:00 2001 From: lizhouze Date: Mon, 20 Jun 2022 16:07:39 +0800 Subject: [PATCH] lizhouze@huawei.com Signed-off-by: lizhouze --- src/loader.js | 13 +++++++++++-- src/util.js | 8 ++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/loader.js b/src/loader.js index bf83674..1b15281 100644 --- a/src/loader.js +++ b/src/loader.js @@ -20,6 +20,7 @@ import loaderUtils from 'loader-utils' import path from 'path' import fs from 'fs' +import md5 from 'md5' import * as legacy from './legacy' import { @@ -31,7 +32,8 @@ import { getRequireString, stringifyLoaders, logWarn, - loadBabelModule + loadBabelModule, + checkDuplicationNormal } from './util' import { isReservedTag } from './templater/component_validator' @@ -294,6 +296,12 @@ function loadPage (_this, name, isEntry, customLang, source) { output += process.env.DEVICE_LEVEL === DEVICE_LEVEL.RICH ? loadPageCheckRich(name, extscript, extcss, isEntry) : loadPageCheckLite(extscript, extcss) + const duplication = checkDuplicationNormal(elementNames); + if (duplication) { + logWarn(_this, [{ + reason: 'ERROR: The element name ' + duplication + ' can not be reoeated.' + }]); + } return output } return output @@ -320,6 +328,8 @@ function loadPageCheckElementLength (_this, elementLength, frag, elementNames, r if (!element.name) { element.name = path.parse(src).name } + elementNames.push(element.name) + element.name = md5(element.name).substring(8, 24) checkEntry(_this, filePath, element.src) } else { @@ -328,7 +338,6 @@ function loadPageCheckElementLength (_this, elementLength, frag, elementNames, r }]) return '' } - elementNames.push(element.name) output += getRequireString(_this, getLoaderString('element', { customLang, name: element.name, diff --git a/src/util.js b/src/util.js index 6e07aa0..0843e1c 100644 --- a/src/util.js +++ b/src/util.js @@ -419,4 +419,12 @@ export function mkDir(path_) { mkDir(parent); } fs.mkdirSync(path_); +} + +export function checkDuplicationNormal(arr) { + arr.some((val, index) => { + if (arr.includes(val, index + 1)){ + return val; + } + }) } \ No newline at end of file -- Gitee