Skip to content

Commit

Permalink
Fix bs.module annotations and make simple ts test (#52)
Browse files Browse the repository at this point in the history
* Remove file extension from module_id for ts files

Fixes printing things like `[@bs.module "modulename.d.ts"]`.

* Add simple.d.ts integration test

* Update snapshot after adding simple.d.ts
  • Loading branch information
zploskey authored and rrdelaney committed Mar 4, 2018
1 parent 77e4e33 commit cca6577
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/__tests__/__snapshots__/compile.js.snap
Expand Up @@ -179,6 +179,11 @@ exports[`Compile simple.re 1`] = `
"
`;
exports[`Compile simple.re 2`] = `
"[@bs.module \\"simple\\"] external add : (~x: float, ~y: float) => float = \\"\\";
"
`;
exports[`Compile simple-class.re 1`] = `
"module Test = {
type t = {. \\"action\\": 't 's .[@bs.meth] (float => string)};
Expand Down
1 change: 1 addition & 0 deletions lib/__tests__/fixtures/simple.d.ts
@@ -0,0 +1 @@
declare function add(x: number, y: number): number
11 changes: 9 additions & 2 deletions src/compiler.re
Expand Up @@ -6,8 +6,15 @@ module Stage = {
let (_, statements, _) = flowAst;
statements;
};
let parseTypescriptSource = (name, source) =>
Typescript.parse(name, source);
let parseTypescriptSource = (filename, source) => {
let last5 = String.sub(filename, String.length(filename) - 5, 5);
let module_name =
switch last5 {
| ".d.ts" => String.sub(filename, 0, String.length(filename) - 5)
| _ => String.sub(filename, 0, String.length(filename) - 3)
};
Typescript.parse(module_name, source);
};
let extension = String.sub(name, String.length(name) - 3, 3);
switch extension {
| ".js" =>
Expand Down

0 comments on commit cca6577

Please sign in to comment.