Skip to content

Commit

Permalink
Merge pull request #13 from rwjblue/fix-named-arg-paths
Browse files Browse the repository at this point in the history
Fix issue with named argument paths.
  • Loading branch information
rwjblue authored Jun 6, 2018
2 parents 68a2e36 + b73c502 commit 8a9d15c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
23 changes: 17 additions & 6 deletions lib/ast-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const reLines = /(.*?(?:\r\n?|\n|$))/gm;
const ALPHA = /[A-Za-z]/;
const WHITESPACE = /[\t\n\f ]/;

class AngleBracketPolyfill {
constructor(options) {
Expand Down Expand Up @@ -101,16 +102,26 @@ class AngleBracketPolyfill {

let nodeSource = sourceForNode(element);

let firstChar;
for (let i = 0; i < nodeSource.length; i++) {
let tagNameStarted = false;
let tagName = '';
for (let i = 1 /* starting after the opening < */; i < nodeSource.length; i++) {
let char = nodeSource[i];
if (char == '@' || ALPHA.test(char)) {
firstChar = char;
break;

if (tagNameStarted) {
if (char === '/' || char === '>' || WHITESPACE.test(char)) {
break;
} else {
tagName += char;
}
} else {
if (char == '@' || ALPHA.test(char)) {
tagNameStarted = true;
tagName += char;
}
}
}

return firstChar + element.tag.slice(1);
return tagName;
}

function getInvocationDetails(element) {
Expand Down
2 changes: 1 addition & 1 deletion lib/sample-compile-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
const compiler = require('ember-source/dist/ember-template-compiler');
compiler.registerPlugin('ast', require('./ast-transform'));

let template = '<span ...attributes>hi martin!</span>';
let template = '<@nav.item />';
let output = compiler.precompile(template, { contents: template });
console.log(output); // eslint-disable-line no-console

0 comments on commit 8a9d15c

Please sign in to comment.