Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f01445
commit cee1344
Showing
3 changed files
with
126 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"use strict"; | ||
|
||
if (typeof exports !== "undefined") { | ||
var assert = require("assert"); | ||
var acorn = require("acorn"); | ||
var jsx = require(".."); | ||
var testAssert = require("./driver.js").testAssert; | ||
} | ||
|
||
testAssert("// the enhanced Parser instance should have a static property 'acornJsx'.", function() { | ||
const JsxParser = acorn.Parser.extend(jsx()); | ||
assert(JsxParser.acornJsx); | ||
}); | ||
|
||
testAssert("// 'acornJsx' should be the same instance for the same acorn.", function() { | ||
const JsxParser1 = acorn.Parser.extend(jsx()); | ||
const JsxParser2 = acorn.Parser.extend(jsx()); | ||
assert.strictEqual(JsxParser1.acornJsx, JsxParser2.acornJsx); | ||
}); | ||
|
||
testAssert("// the static property 'acornJsx' should have two properties.", function() { | ||
const JsxParser = acorn.Parser.extend(jsx()); | ||
assert(JsxParser.acornJsx.tokTypes, "should have 'tokTypes'."); | ||
assert(JsxParser.acornJsx.tokContexts, "should have 'tokContexts'."); | ||
}); | ||
|
||
testAssert("// 'acornJsx.tokTypes' should be used.", function() { | ||
const JsxParser = acorn.Parser.extend(jsx()); | ||
const code = '<a>{/* foo */}</a>'; | ||
const expectedTokTypes = [ | ||
JsxParser.acornJsx.tokTypes.jsxTagStart, | ||
JsxParser.acornJsx.tokTypes.jsxName, | ||
JsxParser.acornJsx.tokTypes.jsxTagEnd, | ||
acorn.tokTypes.braceL, | ||
acorn.tokTypes.braceR, | ||
JsxParser.acornJsx.tokTypes.jsxTagStart, | ||
acorn.tokTypes.slash, | ||
JsxParser.acornJsx.tokTypes.jsxName, | ||
JsxParser.acornJsx.tokTypes.jsxTagEnd, | ||
acorn.tokTypes.eof | ||
] | ||
const actualTokens = [] | ||
|
||
JsxParser.parse(code, {onToken: actualTokens}) | ||
|
||
assert.strictEqual(actualTokens.length, expectedTokTypes.length); | ||
for (let i = 0; i < actualTokens.length; ++i) { | ||
assert.strictEqual(actualTokens[i].type, expectedTokTypes[i]); | ||
} | ||
}); |