Skip to content

Commit

Permalink
Support export all types (ScalablyTyped#586)
Browse files Browse the repository at this point in the history
* Add test for exporting all types (ScalablyTyped#585)

* Fix export all (ScalablyTyped#585)
  • Loading branch information
steinybot authored Dec 12, 2023
1 parent ae10c35 commit dc98c6c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
9 changes: 9 additions & 0 deletions docs/devel/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,17 @@ Developing a compiler is complex. Testing it well is expensive, so we focus on g
For that reason we have a few levels of testing:

### Unit tests

Only really used for the parser, but utterly necessary to write one. All changes to the parser should come with a corresponding unit test.

Take a look at test in [parser](https://github.com/ScalablyTyped/Converter/tree/master/importer/src/test/scala/org/scalablytyped/converter/internal/ts/parser) for examples.

Run them with:

```shell
sbt importer/testOnly org.scalablytyped.converter.internal.ts.parser.*
```

### [ImporterTest](https://github.com/ScalablyTyped/Converter/blob/master/importer/src/test/scala/org/scalablytyped/converter/internal/importer/ImporterTest.scala)
Built in the same spirit as the scala compiler's `partest`, this takes smallish [pieces of typescript](https://github.com/ScalablyTyped/Converter/tree/master/importer/src/test/resources)
code and run it through the entire pipeline, including `scalac`. These are relatively cheap (~30 seconds for all tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,4 +431,16 @@ final class ImportExportParseTests extends AnyFunSuite with Matchers {
),
)
}

test("export all types") {
val content = """export type * from 'types'"""
shouldParseAs(content, TsParser.tsExport)(
TsExport(
NoComments,
typeOnly = true,
ExportType.Named,
TsExportee.Star(None, TsIdentModule.simple("types")),
),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,15 @@ class TsParser(path: Option[(os.Path, Int)]) extends StdTokenParsers with Parser
("type".isDefined ~ base) | (success(false) ~ base)
}

val exporteeStar: Parser[Boolean ~ TsExportee.Star] =
success(false) ~ ("*" ~> ("as" ~> tsIdent).? ~ from ^^ TsExportee.Star.apply)
val exporteeStar: Parser[Boolean ~ TsExportee.Star] = {
val base = "*" ~> ("as" ~> tsIdent).? ~ from ^^ TsExportee.Star.apply
("type".isDefined ~ base) | (success(false) ~ base)
}

val exporteeTree: Parser[Boolean ~ TsExportee.Tree] =
success(false) ~ (tsDecl ^^ TsExportee.Tree)

exporteeTree | exportedNames | exporteeStar
exporteeTree | exporteeStar | exportedNames
}

(comments <~ "export") ~ exportType ~! exportee ^^ {
Expand Down

0 comments on commit dc98c6c

Please sign in to comment.