Skip to content

Commit

Permalink
feat(ast): support module type
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Jun 15, 2016
1 parent 9cf22e0 commit 7e63fa0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
"license": "MIT",
"dependencies": {
"ast-source": "^2.0.0",
"comment-to-assert": "^1.0.2",
"comment-to-assert": "^1.1.0",
"concat-stream": "^1.5.0",
"escodegen": "^1.8.0",
"espower": "^1.0.6",
"espree": "^3.1.5",
"esprima": "^2.5.0",
"estraverse": "^4.1.0",
"power-assert-formatter": "^1.0.1"
Expand Down
2 changes: 0 additions & 2 deletions src/inject-assert.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// LICENSE : MIT
"use strict";
import traverse from "estraverse"
import {Syntax} from "estraverse"
import {parse} from "esprima"
export function injectAssertModule(AST) {
var powerAssertDeclaration = parse(`var assert = require("power-assert")`);
Expand Down
2 changes: 1 addition & 1 deletion src/power-doctest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {toAssertFromAST} from "comment-to-assert"
import {injectAssertModule} from "./inject-assert"
import espower from "espower"
import assert from "assert"
import ASTSource from "ast-source"
import ASTSource from "ast-source";
import {ASTDataContainer} from "ast-source"
export function convertCode(code, filePath) {
var source = new ASTSource(code, {
Expand Down
17 changes: 16 additions & 1 deletion test/power-doctest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ function parseAndConvert(code) {
range: true,
comment: true,
attachComment: true,
tokens: true
tokens: true,
sourceType: 'module'
};
var AST = parse(code, options);
return convertAST(AST);
Expand All @@ -22,6 +23,20 @@ describe("power-doctest", function () {
var a = 1;
`);
});
it("module type", function () {
var code = `
export default function hello(){
var a = 1;
}
`;
var resultAST = parseAndConvert(code);
astEqual(resultAST, `
var assert = require("power-assert");
export default function hello(){
var a = 1;
}
`);
});
it("convert assert to power-assert format", function () {
var code = `var a = 1;
a; // => 1`;
Expand Down

0 comments on commit 7e63fa0

Please sign in to comment.