-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
10 changed files
with
163 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
export class InlineContext { | ||
m_Path: NodePath<BlockStatement>; | ||
|
||
get m_ID() { | ||
return Symbol(); | ||
} | ||
|
||
get m_Code() { | ||
return this.m_Path.node as BlockStatement; | ||
} | ||
} | ||
|
||
<InlineContext /> + | ||
function constructor(this: InlineContext, path: NodePath<BlockStatement>) { | ||
this.m_Path = path; | ||
}; | ||
|
||
<InlineContext /> + | ||
function ToStatements(this: InlineContext) { | ||
return this.m_Code.body; | ||
}; | ||
|
||
<InlineContext /> + | ||
function Resolve(this: InlineContext & IInlineContext, dsl: IDSL) { | ||
this.m_Code.body = dsl.Transcribe(this.ToStatements(), this.m_Path); | ||
}; | ||
|
||
<InlineContext /> + | ||
function GetContextName(this: InlineContext) { | ||
const statement = this.m_Path.node.body[0] as ExpressionStatement; | ||
if (!statement) { | ||
return ""; | ||
} | ||
|
||
const [, dsl_name] = (statement.expression as StringLiteral).value.trim().split(" "); | ||
return dsl_name; | ||
}; | ||
|
||
export interface IInlineContext { | ||
ToStatements: () => Array<Statement>; | ||
} | ||
|
||
import { BlockStatement, StringLiteral, ExpressionStatement, Statement } from "@babel/types"; | ||
import { NodePath } from "@babel/traverse"; | ||
import { IDSL } from "../core/transcriber"; |
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
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,33 @@ | ||
import { ToNodePath, ToAst, InlineContext } from "../../src"; | ||
import { Statement } from "@babel/types"; | ||
|
||
test("get context name", () => { | ||
const context = new InlineContext( | ||
ToNodePath(` | ||
{ | ||
'use foo'; | ||
console.log("previous"); | ||
} | ||
`) | ||
); | ||
expect(context.GetContextName()).toEqual("foo"); | ||
}); | ||
|
||
test("to statement", () => { | ||
// | ||
const context = new InlineContext( | ||
ToNodePath(` | ||
{ | ||
'use foo'; | ||
console.log("previous"); | ||
} | ||
`) | ||
); | ||
|
||
// | ||
const expected = ToAst<Array<Statement>>(` | ||
'use foo'; | ||
console.log("previous"); | ||
`); | ||
expect(context.ToStatements()).toEqual(expected); | ||
}); |
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