Skip to content

Commit

Permalink
Fix #304: Don't escape unreserved keywords (#410)
Browse files Browse the repository at this point in the history
`method` and several other words were previously reservered keywords,
but aren't any more.
See [RFC](https://github.com/fsharp/fslang-design/blob/master/FSharp-4.1/FS-1016-unreserve-keywords.md),
[PR](dotnet/fsharp#1279)
  • Loading branch information
Booksbaum authored Apr 12, 2021
1 parent 751d7a5 commit 239856f
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 10 deletions.
8 changes: 0 additions & 8 deletions src/keywords.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,17 @@ module ts2fable.Keywords

let reserved =
[
"atomic"
"break"
"checked"
"component"
"const"
"constraint"
"constructor"
"continue"
"eager"
"event"
"external"
"fixed"
"functor"
"include"
"measure"
"method"
"mixin"
"object"
"parallel"
"params"
"process"
Expand All @@ -29,7 +22,6 @@ let reserved =
"tailcall"
"trait"
"virtual"
"volatile"
"asr"
"land"
"lor"
Expand Down
59 changes: 59 additions & 0 deletions test/fragments/regressions/#304-reserved-keywords.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Escape all reserved keywords.
*
* Some previously reserved keywords, aren't reserved any more.
* See [RFC](https://github.com/fsharp/fslang-design/blob/master/FSharp-4.1/FS-1016-unreserve-keywords.md), [PR](https://github.com/dotnet/fsharp/pull/1279)
*/
export interface I {
// OCAML keywords

asr: string
land: string
lor: string
lsl: string
lsr: string
lxor: string
mod: string
sig: string

// F# reserved keywords

break: string
checked: string
component: string
const: string
constraint: string
continue: string
event: string
external: string
include: string
mixin: string
parallel: string
process: string
protected: string
pure: string
sealed: string
tailcall: string
trait: string
virtual: string

// not reserved any more
/** Not reserved any more */
atomic: string
/** Not reserved any more */
constructor: string
/** Not reserved any more */
eager: string
/** Not reserved any more */
functor: string
/** Not reserved any more */
measure: string
/** Not reserved any more */
method: string
/** Not reserved any more */
object: string
/** Not reserved any more */
recursive: string
/** Not reserved any more */
volatile: string
}
59 changes: 59 additions & 0 deletions test/fragments/regressions/#304-reserved-keywords.expected.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// ts2fable 0.0.0
module rec ``#304-reserved-keywords``
open System
open Fable.Core
open Fable.Core.JS


/// <summary>
/// Escape all reserved keywords.
///
/// Some previously reserved keywords, aren't reserved any more.
/// See <see href="https://github.com/fsharp/fslang-design/blob/master/FSharp-4.1/FS-1016-unreserve-keywords.md">RFC</see>, <see href="https://github.com/dotnet/fsharp/pull/1279">PR</see>
/// </summary>
type [<AllowNullLiteral>] I =
abstract ``asr``: string with get, set
abstract ``land``: string with get, set
abstract ``lor``: string with get, set
abstract ``lsl``: string with get, set
abstract ``lsr``: string with get, set
abstract ``lxor``: string with get, set
abstract ``mod``: string with get, set
abstract ``sig``: string with get, set
abstract ``break``: string with get, set
abstract ``checked``: string with get, set
abstract ``component``: string with get, set
abstract ``const``: string with get, set
abstract ``constraint``: string with get, set
abstract ``continue``: string with get, set
abstract ``event``: string with get, set
abstract ``external``: string with get, set
abstract ``include``: string with get, set
abstract ``mixin``: string with get, set
abstract ``parallel``: string with get, set
abstract ``process``: string with get, set
abstract ``protected``: string with get, set
abstract ``pure``: string with get, set
abstract ``sealed``: string with get, set
abstract ``tailcall``: string with get, set
abstract ``trait``: string with get, set
abstract ``virtual``: string with get, set
/// Not reserved any more
abstract atomic: string with get, set
/// Not reserved any more
abstract constructor: string with get, set
/// Not reserved any more
abstract eager: string with get, set
/// Not reserved any more
abstract functor: string with get, set
/// Not reserved any more
abstract measure: string with get, set
/// Not reserved any more
abstract method: string with get, set
/// Not reserved any more
abstract object: string with get, set
/// Not reserved any more
abstract recursive: string with get, set
/// Not reserved any more
abstract volatile: string with get, set

8 changes: 6 additions & 2 deletions test/fsFileTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,10 @@ let testFsFileLines tsPaths fsPath (f: string list -> unit) =
it "regression #303 EmitIndexer" <| fun _ ->
runRegressionTest "#303-EmitIndexer"

// https://github.com/fable-compiler/ts2fable/issues/304
it "regression #304 Escaped unreserved keywords" <| fun _ ->
runRegressionTest "#304-reserved-keywords"

// https://github.com/fable-compiler/ts2fable/pull/368
it "regression #368 compare xml comments -- pass" <| fun _ ->
runRegressionTest "#368-compare-xml-comments.pass"
Expand All @@ -501,7 +505,7 @@ let testFsFileLines tsPaths fsPath (f: string list -> unit) =
runRegressionTestWithComparison notEqual "#368-compare-xml-comments.indented.fail"

// https://github.com/fable-compiler/ts2fable/issues/374
it "regression #368 string literal type argument with space" <| fun _ ->
it "regression #374 string literal type argument with space" <| fun _ ->
runRegressionTest "#374-string-literal-type-argument-with-space"

// https://github.com/fable-compiler/ts2fable/issues/375
Expand All @@ -528,7 +532,7 @@ let testFsFileLines tsPaths fsPath (f: string list -> unit) =
it "regression #393 Mutable Variables become immutable" <| fun _ ->
runRegressionTest "#393-mutable-variables-become-immutable"

// https://github.com/fable-compiler/ts2fable/issues/400
// https://github.com/fable-compiler/ts2fable/issues/403
it "regression #403 Invalid Xml Comments because of unescaped chars" <| fun _ ->
runRegressionTest "#403-xml-comment-escape-chars"

Expand Down

0 comments on commit 239856f

Please sign in to comment.