Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape text output in HTML Emitter #13

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/emitter/ecmarkup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Emitter } from "./emitter";
import { SyntaxKind } from "../tokens";
import { DiagnosticMessages } from "../diagnostics";
import { Checker } from "../checker";
var escape = require("html-escape");

import {
Node,
SourceFile,
Expand Down Expand Up @@ -154,7 +156,7 @@ export class EcmarkupEmitter extends Emitter {
this.writer.write(` optional`);
}
this.writer.write(`>`);
this.writer.write(node.text);
this.writer.write(escape(node.text));
this.writer.write(`</emu-t>`);
}

Expand Down Expand Up @@ -302,7 +304,7 @@ export class EcmarkupEmitter extends Emitter {
}

protected emitTextContent(node: TextContent) {
let text = node.text;
let text = escape(node.text);
this.writer.write(text);
}

Expand All @@ -322,4 +324,4 @@ export class EcmarkupEmitter extends Emitter {
this.emitNode(node);
}
}
}
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,8 @@
"mocha": "^2.2.5",
"source-map-support": "^0.3.1",
"typescript": "^1.5.0-beta"
},
"dependencies": {
"html-escape": "^1.0.2"
}
}
3 changes: 3 additions & 0 deletions spec/es6.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -985,3 +985,6 @@ ExportsList :
ExportSpecifier :
IdentifierName
IdentifierName `as` IdentifierName

SingleLineHTMLOpenComment ::
`<!--` SingleLineCommentChars?
38 changes: 22 additions & 16 deletions tests/baselines/reference/[ECMarkup]es6.grammar.emu.html
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,14 @@
</emu-production>
<emu-production name="StringLiteral" type="lexical">
<emu-rhs a="15d8b1f1">
<emu-t>"</emu-t>
<emu-t>&quot;</emu-t>
<emu-nt optional>DoubleStringCharacters</emu-nt>
<emu-t>"</emu-t>
<emu-t>&quot;</emu-t>
</emu-rhs>
<emu-rhs a="82ecb3d9">
<emu-t>'</emu-t>
<emu-t>&#39;</emu-t>
<emu-nt optional>SingleStringCharacters</emu-nt>
<emu-t>'</emu-t>
<emu-t>&#39;</emu-t>
</emu-rhs>
</emu-production>
<emu-production name="DoubleStringCharacters" type="lexical">
Expand All @@ -329,15 +329,15 @@
</emu-rhs>
</emu-production>
<emu-production name="DoubleStringCharacter" type="lexical">
<emu-rhs a="25593d43"><emu-nt>SourceCharacter</emu-nt><emu-gmod>but not one of <emu-t>"</emu-t> or <emu-t>\</emu-t> or <emu-nt>LineTerminator</emu-nt></emu-gmod></emu-rhs>
<emu-rhs a="25593d43"><emu-nt>SourceCharacter</emu-nt><emu-gmod>but not one of <emu-t>&quot;</emu-t> or <emu-t>\</emu-t> or <emu-nt>LineTerminator</emu-nt></emu-gmod></emu-rhs>
<emu-rhs a="ea7d8d26">
<emu-t>\</emu-t>
<emu-nt>EscapeSequence</emu-nt>
</emu-rhs>
<emu-rhs a="00992933"><emu-nt>LineContinuation</emu-nt></emu-rhs>
</emu-production>
<emu-production name="SingleStringCharacter" type="lexical">
<emu-rhs a="c574e0b6"><emu-nt>SourceCharacter</emu-nt><emu-gmod>but not one of <emu-t>'</emu-t> or <emu-t>\</emu-t> or <emu-nt>LineTerminator</emu-nt></emu-gmod></emu-rhs>
<emu-rhs a="c574e0b6"><emu-nt>SourceCharacter</emu-nt><emu-gmod>but not one of <emu-t>&#39;</emu-t> or <emu-t>\</emu-t> or <emu-nt>LineTerminator</emu-nt></emu-gmod></emu-rhs>
<emu-rhs a="ea7d8d26">
<emu-t>\</emu-t>
<emu-nt>EscapeSequence</emu-nt>
Expand Down Expand Up @@ -923,40 +923,40 @@
<emu-rhs a="2baeb5db"><emu-nt params="?Yield">AdditiveExpression</emu-nt></emu-rhs>
<emu-rhs a="1e6dbeb2">
<emu-nt params="?Yield">ShiftExpression</emu-nt>
<emu-t><<</emu-t>
<emu-t>&lt;&lt;</emu-t>
<emu-nt params="?Yield">AdditiveExpression</emu-nt>
</emu-rhs>
<emu-rhs a="639cdc26">
<emu-nt params="?Yield">ShiftExpression</emu-nt>
<emu-t>>></emu-t>
<emu-t>&gt;&gt;</emu-t>
<emu-nt params="?Yield">AdditiveExpression</emu-nt>
</emu-rhs>
<emu-rhs a="9d297ffd">
<emu-nt params="?Yield">ShiftExpression</emu-nt>
<emu-t>>>></emu-t>
<emu-t>&gt;&gt;&gt;</emu-t>
<emu-nt params="?Yield">AdditiveExpression</emu-nt>
</emu-rhs>
</emu-production>
<emu-production name="RelationalExpression" params="In, Yield">
<emu-rhs a="14cbe144"><emu-nt params="?Yield">ShiftExpression</emu-nt></emu-rhs>
<emu-rhs a="862f8bef">
<emu-nt params="?In, ?Yield">RelationalExpression</emu-nt>
<emu-t><</emu-t>
<emu-t>&lt;</emu-t>
<emu-nt params="?Yield">ShiftExpression</emu-nt>
</emu-rhs>
<emu-rhs a="e1b30960">
<emu-nt params="?In, ?Yield">RelationalExpression</emu-nt>
<emu-t>></emu-t>
<emu-t>&gt;</emu-t>
<emu-nt params="?Yield">ShiftExpression</emu-nt>
</emu-rhs>
<emu-rhs a="707c38bf">
<emu-nt params="?In, ?Yield">RelationalExpression</emu-nt>
<emu-t><=</emu-t>
<emu-t>&lt;=</emu-t>
<emu-nt params="?Yield">ShiftExpression</emu-nt>
</emu-rhs>
<emu-rhs a="cc6c18fa">
<emu-nt params="?In, ?Yield">RelationalExpression</emu-nt>
<emu-t>>=</emu-t>
<emu-t>&gt;=</emu-t>
<emu-nt params="?Yield">ShiftExpression</emu-nt>
</emu-rhs>
<emu-rhs a="3bd34097">
Expand Down Expand Up @@ -997,7 +997,7 @@
<emu-rhs a="003e4dd5"><emu-nt params="?In, ?Yield">EqualityExpression</emu-nt></emu-rhs>
<emu-rhs a="dc348a15">
<emu-nt params="?In, ?Yield">BitwiseANDExpression</emu-nt>
<emu-t>&</emu-t>
<emu-t>&amp;</emu-t>
<emu-nt params="?In, ?Yield">EqualityExpression</emu-nt>
</emu-rhs>
</emu-production>
Expand All @@ -1021,7 +1021,7 @@
<emu-rhs a="43e84f3f"><emu-nt params="?In, ?Yield">BitwiseORExpression</emu-nt></emu-rhs>
<emu-rhs a="de0d5414">
<emu-nt params="?In, ?Yield">LogicalANDExpression</emu-nt>
<emu-t>&&</emu-t>
<emu-t>&amp;&amp;</emu-t>
<emu-nt params="?In, ?Yield">BitwiseORExpression</emu-nt>
</emu-rhs>
</emu-production>
Expand Down Expand Up @@ -1640,7 +1640,7 @@
<emu-rhs a="5a88b959">
<emu-nt params="?Yield">ArrowParameters</emu-nt>
<emu-gann>no <emu-nt>LineTerminator</emu-nt> here</emu-gann>
<emu-t>=></emu-t>
<emu-t>=&gt;</emu-t>
<emu-nt params="?In">ConciseBody</emu-nt>
</emu-rhs>
</emu-production>
Expand Down Expand Up @@ -1991,4 +1991,10 @@
<emu-t>as</emu-t>
<emu-nt>IdentifierName</emu-nt>
</emu-rhs>
</emu-production>
<emu-production name="SingleLineHTMLOpenComment" type="lexical">
<emu-rhs a="f50b0f2f">
<emu-t>&lt;!--</emu-t>
<emu-nt optional>SingleLineCommentChars</emu-nt>
</emu-rhs>
</emu-production>
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
</emu-production>
<emu-production name="UnicodeCharacterLiteral" type="lexical">
<emu-rhs a="eb4a6a4b">
<emu-t><</emu-t>
<emu-t>&lt;</emu-t>
<emu-nt>UnicodeCharacterLiteralChars</emu-nt>
<emu-t>></emu-t>
<emu-t>&gt;</emu-t>
</emu-rhs>
</emu-production>
<emu-production name="UnicodeCharacterLiteralChars" type="lexical">
Expand All @@ -56,7 +56,7 @@
</emu-rhs>
</emu-production>
<emu-production name="UnicodeCharacterLiteralChar" type="lexical">
<emu-rhs a="3490f5bb"><emu-nt>SourceCharacter</emu-nt><emu-gmod>but not one of <emu-t><</emu-t> or <emu-t>></emu-t> or <emu-nt>LineTerminator</emu-nt></emu-gmod></emu-rhs>
<emu-rhs a="3490f5bb"><emu-nt>SourceCharacter</emu-nt><emu-gmod>but not one of <emu-t>&lt;</emu-t> or <emu-t>&gt;</emu-t> or <emu-nt>LineTerminator</emu-nt></emu-gmod></emu-rhs>
</emu-production>
<emu-production name="Indent" type="lexical">
<emu-rhs a="e1ed22ce"><emu-gprose>An increase in the indentation depth from the previous line.</emu-gprose></emu-rhs>
Expand Down Expand Up @@ -98,7 +98,7 @@
</emu-production>
<emu-production name="ProseLine" type="lexical">
<emu-rhs a="a16b392e">
<emu-t>></emu-t>
<emu-t>&gt;</emu-t>
<emu-nt optional>ProseChars</emu-nt>
</emu-rhs>
</emu-production>
Expand Down Expand Up @@ -219,14 +219,14 @@
<emu-production name="LookaheadInAssertionClause">
<emu-rhs a="d21a8670">
<emu-t>lookahead</emu-t>
<emu-t><-</emu-t>
<emu-t>&lt;-</emu-t>
<emu-nt>SymbolSet</emu-nt>
</emu-rhs>
</emu-production>
<emu-production name="LookaheadNotInAssertionClause">
<emu-rhs a="175dd806">
<emu-t>lookahead</emu-t>
<emu-t><!</emu-t>
<emu-t>&lt;!</emu-t>
<emu-nt>SymbolSet</emu-nt>
</emu-rhs>
</emu-production>
Expand Down
20 changes: 10 additions & 10 deletions tests/baselines/reference/[ECMarkup]typescript.grammar.emu.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<emu-production name="TypeParameters">
<emu-rhs a="27ce0641">
<emu-t><</emu-t>
<emu-t>&lt;</emu-t>
<emu-nt>TypeParameterList</emu-nt>
<emu-t>></emu-t>
<emu-t>&gt;</emu-t>
</emu-rhs>
</emu-production>
<emu-production name="TypeParameterList">
Expand All @@ -27,9 +27,9 @@
</emu-production>
<emu-production name="TypeArguments">
<emu-rhs a="8f8c81b6">
<emu-t><</emu-t>
<emu-t>&lt;</emu-t>
<emu-nt>TypeArgumentList</emu-nt>
<emu-t>></emu-t>
<emu-t>&gt;</emu-t>
</emu-rhs>
</emu-production>
<emu-production name="TypeArgumentList">
Expand Down Expand Up @@ -165,7 +165,7 @@
<emu-t>(</emu-t>
<emu-nt optional>ParameterList</emu-nt>
<emu-t>)</emu-t>
<emu-t>=></emu-t>
<emu-t>=&gt;</emu-t>
<emu-nt>Type</emu-nt>
</emu-rhs>
</emu-production>
Expand All @@ -176,7 +176,7 @@
<emu-t>(</emu-t>
<emu-nt optional>ParameterList</emu-nt>
<emu-t>)</emu-t>
<emu-t>=></emu-t>
<emu-t>=&gt;</emu-t>
<emu-nt>Type</emu-nt>
</emu-rhs>
</emu-production>
Expand Down Expand Up @@ -444,12 +444,12 @@
<emu-production name="ArrowFunctionExpression">
<emu-rhs a="55d6be67">
<emu-nt>ArrowFormalParameters</emu-nt>
<emu-t>=></emu-t>
<emu-t>=&gt;</emu-t>
<emu-nt>Block</emu-nt>
</emu-rhs>
<emu-rhs a="05b42266">
<emu-nt>ArrowFormalParameters</emu-nt>
<emu-t>=></emu-t>
<emu-t>=&gt;</emu-t>
<emu-nt>AssignmentExpression</emu-nt>
</emu-rhs>
</emu-production>
Expand All @@ -467,9 +467,9 @@
</emu-production>
<emu-production name="UnaryExpression">
<emu-rhs a="70eae169">
<emu-t><</emu-t>
<emu-t>&lt;</emu-t>
<emu-nt>Type</emu-nt>
<emu-t>></emu-t>
<emu-t>&gt;</emu-t>
<emu-nt>UnaryExpression</emu-nt>
</emu-rhs>
</emu-production>
Expand Down
3 changes: 3 additions & 0 deletions tests/baselines/reference/[Markdown]es6.grammar.md
Original file line number Diff line number Diff line change
Expand Up @@ -971,4 +971,7 @@
&emsp;&emsp;<a name="ExportSpecifier"></a>*ExportSpecifier* **:**
&emsp;&emsp;&emsp;<a name="ExportSpecifier-0ebb31e2"></a>*[IdentifierName](#IdentifierName)*
&emsp;&emsp;&emsp;<a name="ExportSpecifier-a9552c46"></a>*[IdentifierName](#IdentifierName)*&emsp;`` as ``&emsp;*[IdentifierName](#IdentifierName)*

&emsp;&emsp;<a name="SingleLineHTMLOpenComment"></a>*SingleLineHTMLOpenComment* **::**
&emsp;&emsp;&emsp;<a name="SingleLineHTMLOpenComment-f50b0f2f"></a>`` <!-- ``&emsp;*[SingleLineCommentChars](#SingleLineCommentChars)*<sub>opt</sub>

12 changes: 12 additions & 0 deletions tests/baselines/reference/[Parser]es6.grammar.nodes
Original file line number Diff line number Diff line change
Expand Up @@ -7916,3 +7916,15 @@
(987,21)SyntaxKind[Nonterminal]
(987,21)SyntaxKind[Identifier](text = "IdentifierName")
(987,36)SyntaxKind[DedentToken]
(989,1)SyntaxKind[Production]
(989,1)SyntaxKind[Identifier](text = "SingleLineHTMLOpenComment")
(989,29)SyntaxKind[RightHandSideList]
(989,29)SyntaxKind[IndentToken]
(990,9)SyntaxKind[RightHandSide]
(990,9)SyntaxKind[SymbolSpan]
(990,9)SyntaxKind[Terminal](text = "<!--")
(990,15)SyntaxKind[SymbolSpan]
(990,15)SyntaxKind[Nonterminal]?
(990,15)SyntaxKind[Identifier](text = "SingleLineCommentChars")
(990,38)SyntaxKind[QuestionToken]
(990,39)SyntaxKind[DedentToken]
12 changes: 11 additions & 1 deletion tests/baselines/reference/[Scanner]es6.grammar.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -5579,4 +5579,14 @@ SyntaxKind[Terminal](987,21): `as`
SyntaxKind[Identifier](987,36): IdentifierName
SyntaxKind[LineTerminatorToken](988,1): «line terminator»
SyntaxKind[DedentToken](988,1): «dedent»
SyntaxKind[EndOfFileToken](988,1): «EndOfFileToken»
SyntaxKind[LineTerminatorToken](989,1): «line terminator»
SyntaxKind[Identifier](989,26): SingleLineHTMLOpenComment
SyntaxKind[ColonColonToken](989,29): ::
SyntaxKind[LineTerminatorToken](990,9): «line terminator»
SyntaxKind[IndentToken](990,9): «indent»
SyntaxKind[Terminal](990,15): `<!--`
SyntaxKind[Identifier](990,38): SingleLineCommentChars
SyntaxKind[QuestionToken](990,39): ?
SyntaxKind[LineTerminatorToken](991,1): «line terminator»
SyntaxKind[DedentToken](991,1): «dedent»
SyntaxKind[EndOfFileToken](991,1): «EndOfFileToken»