Permalink
Browse files

fixing bug if there are no matched attributes

  • Loading branch information...
justinbmeyer committed Nov 1, 2018
1 parent 877047a commit 20e9ab618ce55427bd8db93c9c895ebb8c8c20cb
Showing with 25 additions and 23 deletions.
  1. +8 −7 lib/transforms/version-4/can-stache/attr-from.js
  2. +17 −16 src/templates/can-stache/attr-from.js
@@ -91,19 +91,20 @@ function transformer(file) {
var alphaNumericHU = '-:_' + alphaNumeric;
var attributeRegexp = new RegExp('[' + alphaNumericHU + ']+\s*=\s*("[^"]*"|\'[^\']*\')', 'gm');
var attributes = src.match(attributeRegexp);
if(attributes) {
for (let i=0, parserIndex=0; i<attributes.length; i++) {
const attribute = attributes[i].slice(0, attributes[i].indexOf('='));
const value = attributes[i].slice(attributes[i].indexOf('=') + 1);
if (attributes) {
for (var i = 0, parserIndex = 0; i < attributes.length; i++) {
var attribute = attributes[i].slice(0, attributes[i].indexOf('='));
var value = attributes[i].slice(attributes[i].indexOf('=') + 1);

let parsedAttribute = parsedAttributes[parserIndex];
var parsedAttribute = parsedAttributes[parserIndex];
// skip any attributes not found during parsing since they do not need to be modified
if (parsedAttribute && parsedAttribute.name === attribute) {
parserIndex++;

if (parsedAttribute.shouldBeModified) {
src = src.replace(attribute, attribute + ':from');
if (value.includes("'")) { // jshint ignore:line
if (value.includes("'")) {
// jshint ignore:line
src = src.replace(value, '"' + value + '"'); // jshint ignore:line
} else {
src = src.replace(value, "'" + value + "'"); // jshint ignore:line
@@ -116,4 +117,4 @@ function transformer(file) {

return src;
}
module.exports = exports['default'];
module.exports = exports['default'];
@@ -86,22 +86,23 @@ export default function transformer(file) {
const alphaNumericHU = '-:_' + alphaNumeric;
const attributeRegexp = new RegExp('[' + alphaNumericHU + ']+\s*=\s*("[^"]*"|\'[^\']*\')', 'gm');
const attributes = src.match(attributeRegexp);

for (let i=0, parserIndex=0; i<attributes.length; i++) {
const attribute = attributes[i].slice(0, attributes[i].indexOf('='));
const value = attributes[i].slice(attributes[i].indexOf('=') + 1);

let parsedAttribute = parsedAttributes[parserIndex];
// skip any attributes not found during parsing since they do not need to be modified
if (parsedAttribute && parsedAttribute.name === attribute) {
parserIndex++;

if (parsedAttribute.shouldBeModified) {
src = src.replace(attribute, attribute + ':from');
if (value.includes("'")) { // jshint ignore:line
src = src.replace(value, '"' + value + '"'); // jshint ignore:line
} else {
src = src.replace(value, "'" + value + "'"); // jshint ignore:line
if(attributes) {
for (let i=0, parserIndex=0; i<attributes.length; i++) {
const attribute = attributes[i].slice(0, attributes[i].indexOf('='));
const value = attributes[i].slice(attributes[i].indexOf('=') + 1);

let parsedAttribute = parsedAttributes[parserIndex];
// skip any attributes not found during parsing since they do not need to be modified
if (parsedAttribute && parsedAttribute.name === attribute) {
parserIndex++;

if (parsedAttribute.shouldBeModified) {
src = src.replace(attribute, attribute + ':from');
if (value.includes("'")) { // jshint ignore:line
src = src.replace(value, '"' + value + '"'); // jshint ignore:line
} else {
src = src.replace(value, "'" + value + "'"); // jshint ignore:line
}
}
}
}

0 comments on commit 20e9ab6

Please sign in to comment.