Skip to content

Commit

Permalink
use dsl match: instanceof
Browse files Browse the repository at this point in the history
  • Loading branch information
mistlog committed Jun 25, 2020
1 parent 5ce79a9 commit 8024b12
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 42 deletions.
24 changes: 4 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -59,7 +59,7 @@
"@types/jest": "^24.0.18",
"@types/node": "^12.12.14",
"@types/toposort": "2.0.3",
"draft-dsl-match": "0.0.3",
"draft-dsl-match": "^0.1.0",
"husky": "^4.2.5",
"jest": "^24.9.0",
"litscript": "^1.1.6",
Expand Down
44 changes: 23 additions & 21 deletions src/plug-in/draft-plugin-refresh.tsx
@@ -1,17 +1,15 @@
import { IPlugin, ITranscriber } from "../core/transcriber";
import { ITranscriber } from "../core/transcriber";
import { ExportClassCode } from "../code-object/export-class";
import { MethodCode } from "../code-object/method";
import { LocalContext } from "../code-object/local-context";
import { InlineContext } from "../code-object/inline-context";

export class RefreshDraftPlugin implements IPlugin {
export class RefreshDraftPlugin {
m_Transcriber: ITranscriber;
}

constructor(transcriber: ITranscriber) {
this.m_Transcriber = transcriber;
}

Transcribe() {
<RefreshDraftPlugin /> +
function Transcribe(this: RefreshDraftPlugin) {
/**
* clear
*/
Expand All @@ -25,19 +23,23 @@ export class RefreshDraftPlugin implements IPlugin {
*/
const draft = this.m_Transcriber.m_Module.ToDraft();
draft.forEach(each => {
if (each instanceof ExportClassCode) {
this.m_Transcriber.m_ClassMap.set(each.m_Name, each);
} else if (each instanceof MethodCode) {
const class_name = each.m_ClassName;
const methods = this.m_Transcriber.m_MethodMap.get(class_name);
methods
? methods.push(each)
: this.m_Transcriber.m_MethodMap.set(class_name, [each]);
} else if (each instanceof LocalContext) {
this.m_Transcriber.m_ContextMap.set(each.m_Name, each);
} else if (each instanceof InlineContext) {
this.m_Transcriber.m_InlineContextMap.set(each.m_ID, each);
{
"use match";
(each: ExportClassCode) => this.m_Transcriber.m_ClassMap.set(each.m_Name, each);
(each: LocalContext) => this.m_Transcriber.m_ContextMap.set(each.m_Name, each);
(each: InlineContext) => this.m_Transcriber.m_InlineContextMap.set(each.m_ID, each);
(each: MethodCode) => {
const class_name = each.m_ClassName;
const methods = this.m_Transcriber.m_MethodMap.get(class_name);
methods
? methods.push(each)
: this.m_Transcriber.m_MethodMap.set(class_name, [each]);
};
}
});
}
}
};

<RefreshDraftPlugin /> +
function constructor(transcriber: ITranscriber) {
this.m_Transcriber = transcriber;
};
5 changes: 5 additions & 0 deletions typedraft.config.js
@@ -0,0 +1,5 @@
const { PatternMatch } = require("draft-dsl-match");

module.exports = {
DSLs: [{ name: "match", dsl: () => new PatternMatch(true) }],
};

0 comments on commit 8024b12

Please sign in to comment.