From 46ec3111422e6ad08b4e3124f8be33c588117b38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Mu=C3=B1oz?= Date: Sat, 6 Jun 2015 17:21:31 -0700 Subject: [PATCH] Fix location info in ComponentNode --- packages/htmlbars-syntax/lib/builders.js | 5 +++-- .../htmlbars-syntax/lib/token-handlers.js | 2 +- .../htmlbars-syntax/tests/loc-node-test.js | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/packages/htmlbars-syntax/lib/builders.js b/packages/htmlbars-syntax/lib/builders.js index e2373b98..116611e4 100644 --- a/packages/htmlbars-syntax/lib/builders.js +++ b/packages/htmlbars-syntax/lib/builders.js @@ -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) }; } diff --git a/packages/htmlbars-syntax/lib/token-handlers.js b/packages/htmlbars-syntax/lib/token-handlers.js index abe08b50..846f481e 100644 --- a/packages/htmlbars-syntax/lib/token-handlers.js +++ b/packages/htmlbars-syntax/lib/token-handlers.js @@ -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); } diff --git a/packages/htmlbars-syntax/tests/loc-node-test.js b/packages/htmlbars-syntax/tests/loc-node-test.js index dd2b0816..97392f39 100644 --- a/packages/htmlbars-syntax/tests/loc-node-test.js +++ b/packages/htmlbars-syntax/tests/loc-node-test.js @@ -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(` + + + + + + + `); + + 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'); +});