Skip to content
This repository has been archived by the owner on Apr 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #362 from mmun/loc-component
Browse files Browse the repository at this point in the history
Fix location info in ComponentNode
  • Loading branch information
mmun committed Jun 7, 2015
2 parents f174a9c + 46ec311 commit 0221aa8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
5 changes: 3 additions & 2 deletions packages/htmlbars-syntax/lib/builders.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ export function buildElement(tag, attributes, modifiers, children) {
};
}

export function buildComponent(tag, attributes, program) {
export function buildComponent(tag, attributes, program, loc) {
return {
type: "ComponentNode",
tag: tag,
attributes: attributes,
program: program
program: program,
loc: buildLoc(loc)
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/htmlbars-syntax/lib/token-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ var tokenHandlers = {
} else {
var program = buildProgram(element.children);
parseComponentBlockParams(element, program);
var component = buildComponent(element.tag, element.attributes, program);
var component = buildComponent(element.tag, element.attributes, program, element.loc);
appendChild(parent, component);
}

Expand Down
19 changes: 19 additions & 0 deletions packages/htmlbars-syntax/tests/loc-node-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,22 @@ test("html elements", function() {
locEqual(div, 4, 6, 6, 12, 'div element');
locEqual(hr, 5, 8, 5, 14, 'hr element');
});

test("components", function() {
var ast = parse(`
<el-page>
<el-header></el-header>
<el-input />
<el-footer>
</el-footer>
</el-page>
`);

let [,page] = ast.body;
let [,header,,input,,footer] = page.program.body;

locEqual(page, 2, 4, 7, 14, 'page component');
locEqual(header, 3, 6, 3, 29, 'header component');
locEqual(input, 4, 6, 4, 18, 'input component');
locEqual(footer, 5, 6, 6, 22, 'footer component');
});

0 comments on commit 0221aa8

Please sign in to comment.