Skip to content

Commit

Permalink
release 0.2.2
Browse files Browse the repository at this point in the history
1. use config file in ts;
2. fix crash when dsl is empty
  • Loading branch information
mistlog committed Jul 11, 2020
1 parent b831332 commit 0b64099
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 14 deletions.
29 changes: 24 additions & 5 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typedraft",
"version": "0.2.0",
"version": "0.2.2",
"description": "TypeDraft is a superset of typescript with built-in support for DSL extension and literate programming.",
"keywords": [
"literate programming",
Expand Down Expand Up @@ -69,7 +69,7 @@
"pretty-quick": "^2.0.1",
"ts-jest": "^24.0.2",
"ts-node": "^8.3.0",
"typedraft": "0.2.0"
"typedraft": "0.2.2"
},
"husky": {
"hooks": {
Expand Down
11 changes: 9 additions & 2 deletions src/plug-in/draft-plugin-dsl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ export class DSLPlugin {

<DSLPlugin /> +
function Transcribe(this: DSLPlugin) {
const ResolveDSL = (context: InlineContext | LocalContext) =>
context.Resolve(this.m_Transcriber.GetDSL(context.GetDSLName()));
const ResolveDSL = (context: InlineContext | LocalContext) => {
const dsl = this.m_Transcriber.GetDSL(context.GetDSLName());
/**
* DSL name can be "" in local context, then dsl will be undefined
*/
if (dsl) {
context.Resolve(dsl);
}
};
this.m_Transcriber.TraverseInlineContext(ResolveDSL);
this.m_Transcriber.TraverseLocalContext(ResolveDSL);
};
6 changes: 6 additions & 0 deletions test/plug-in/__snapshots__/dsl.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ exports[`nested dsl 1`] = `
}"
`;

exports[`no dsl 1`] = `
"export function Main() {
console.log(\\"previous\\");
}"
`;

exports[`simple 1`] = `
"export function Main() {
console.log(\\"current\\");
Expand Down
16 changes: 16 additions & 0 deletions test/plug-in/dsl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ test("simple", () => {
expect(result).toMatchSnapshot();
});

test("no dsl", () => {
//
const code = `
export function Main(){
<Test/>;
}
function Test(){
console.log("previous");
}
`;
const transcriber = MakeDefaultTranscriber(code);
const result = transcriber.Transcribe();
expect(result).toMatchSnapshot();
});

/**
* <TestLog/> is not used as local context, but after DSL "match" resolved,
* it will be used as local context,
Expand Down
5 changes: 0 additions & 5 deletions typedraft.config.js

This file was deleted.

5 changes: 5 additions & 0 deletions typedraft.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { PatternMatch } from "draft-dsl-match";

export default {
DSLs: [{ name: "match", dsl: () => new PatternMatch(true) }],
};

0 comments on commit 0b64099

Please sign in to comment.