Skip to content

Commit

Permalink
Only error for empty HTML dependency attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Nov 29, 2021
1 parent cdc1d0e commit c13917f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
6 changes: 3 additions & 3 deletions packages/core/integration-tests/test/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -2718,7 +2718,7 @@ describe('html', function () {
name: 'BuildError',
diagnostics: [
{
message: 'src should not be empty string',
message: "'src' should not be empty string",
origin: '@parcel/transformer-html',
codeFrames: [
{
Expand All @@ -2744,7 +2744,7 @@ describe('html', function () {
},

{
message: 'src should not be empty string',
message: "'src' should not be empty string",
origin: '@parcel/transformer-html',
codeFrames: [
{
Expand All @@ -2770,7 +2770,7 @@ describe('html', function () {
},

{
message: 'href should not be empty string',
message: "'href' should not be empty string",
origin: '@parcel/transformer-html',
codeFrames: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<img src="" />
<script src=""></script>
<link href="" />
<link href="" />
<input value="" checked data-x />
18 changes: 9 additions & 9 deletions packages/transformers/html/src/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,17 @@ export default function collectDependencies(
continue;
}

// Check for empty string
if (attrs[attr].length === 0) {
errors.push({
message: `${attr} should not be empty string`,
filePath: asset.filePath,
loc: node.location,
});
}

let elements = ATTRS[attr];
if (elements && elements.includes(node.tag)) {
// Check for empty string
if (attrs[attr].length === 0) {
errors.push({
message: `'${attr}' should not be empty string`,
filePath: asset.filePath,
loc: node.location,
});
}

let depHandler = getAttrDepHandler(attr);
let depOptionsHandler = OPTIONS[node.tag];
let depOptions =
Expand Down
18 changes: 9 additions & 9 deletions packages/transformers/svg/src/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,17 @@ export default function collectDependencies(asset: MutableAsset, ast: AST) {
continue;
}

// Check for empty string
if (attrs[attr].length === 0) {
errors.push({
message: `${attr} should not be empty string`,
filePath: asset.filePath,
loc: node.location,
});
}

const elements = ATTRS[attr];
if (elements && elements.includes(node.tag)) {
// Check for empty string
if (attrs[attr].length === 0) {
errors.push({
message: `'${attr}' should not be empty string`,
filePath: asset.filePath,
loc: node.location,
});
}

let options = OPTIONS[tag]?.[attr];
if (node.tag === 'script') {
options = {
Expand Down

0 comments on commit c13917f

Please sign in to comment.