Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#### :nail_care: Polish

- Add [`Deno`](https://deno.land/api?s=Deno) to reserved names, so that modules named `Deno` don't clash with the globally exposed `Deno` object. https://github.com/rescript-lang/rescript-compiler/pull/6428
- Disable ESLint/TSLint on gentype outputs properly. https://github.com/rescript-lang/rescript-compiler/pull/6442

# 11.0.0-rc.4

Expand Down
27 changes: 8 additions & 19 deletions jscomp/gentype/EmitType.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ open GenTypeCommon
let fileHeader ~sourceFile =
let makeHeader ~lines =
match lines with
| [line] -> "/* " ^ line ^ " */\n"
| [line] -> "/* " ^ line ^ " */\n\n"
| _ ->
"/** \n"
^ (lines |> List.map (fun line -> " * " ^ line) |> String.concat "\n")
^ "\n */\n"
^ "\n */\n\n"
in
makeHeader
~lines:["TypeScript file generated from " ^ sourceFile ^ " by genType."]
^ "/* eslint-disable import/first */\n\n"
^ "/* eslint-disable */\n" ^ "/* tslint:disable */\n"

let interfaceName ~(config : Config.t) name =
match config.exportInterfaces with
Expand Down Expand Up @@ -183,8 +183,7 @@ let rec renderType ~(config : Config.t) ?(indent = None) ~typeNameIsInterface
in
let tagField =
case |> labelJSToString
|> field
~name:(Runtime.jsVariantTag ~polymorphic:false ~tag)
|> field ~name:(Runtime.jsVariantTag ~polymorphic:false ~tag)
in
match (unboxed, type_) with
| true, type_ ->
Expand Down Expand Up @@ -355,20 +354,15 @@ let emitExportType ~(config : Config.t) ~emitters ~nameAs ~opaque ~type_
| true -> "any"
| false -> typeVars |> String.concat " | "
in
"// tslint:disable-next-line:max-classes-per-file \n"
^ (match String.capitalize_ascii resolvedTypeName <> resolvedTypeName with
| true -> "// tslint:disable-next-line:class-name\n"
| false -> "")
^ docString ^ "export abstract class " ^ resolvedTypeName ^ typeParamsString
docString ^ "export abstract class " ^ resolvedTypeName ^ typeParamsString
^ " { protected opaque!: " ^ typeOfOpaqueField
^ " }; /* simulate opaque types */" ^ exportNameAs
|> Emitters.export ~emitters
else
(if isInterface && config.exportInterfaces then
docString ^ "export interface " ^ resolvedTypeName ^ typeParamsString ^ " "
else
"// tslint:disable-next-line:interface-over-type-literal\n" ^ docString
^ "export type " ^ resolvedTypeName ^ typeParamsString ^ " = ")
docString ^ "export type " ^ resolvedTypeName ^ typeParamsString ^ " = ")
^ (match type_ with
| _ -> type_ |> typeToString ~config ~typeNameIsInterface)
^ ";" ^ exportNameAs
Expand All @@ -386,11 +380,6 @@ let emitImportValueAsEarly ~emitters ~name ~nameAs importPath =

let emitRequire ~importedValueOrComponent ~early ~emitters ~(config : Config.t)
~moduleName importPath =
let commentBeforeRequire =
match importedValueOrComponent with
| true -> "// tslint:disable-next-line:no-var-requires\n"
| false -> "// @ts-ignore: Implicit any on import\n"
in
let importPath =
match config.moduleResolution with
| Node ->
Expand All @@ -402,15 +391,15 @@ let emitRequire ~importedValueOrComponent ~early ~emitters ~(config : Config.t)
| ES6 when not importedValueOrComponent ->
let moduleNameString = ModuleName.toString moduleName in
(let es6ImportModule = moduleNameString ^ "__Es6Import" in
commentBeforeRequire ^ "import * as " ^ es6ImportModule ^ " from '"
"import * as " ^ es6ImportModule ^ " from '"
^ (importPath |> ImportPath.emit)
^ "';\n" ^ "const " ^ moduleNameString ^ ": any = " ^ es6ImportModule ^ ";")
|> (match early with
| true -> Emitters.requireEarly
| false -> Emitters.require)
~emitters
| _ ->
commentBeforeRequire ^ "const "
"const "
^ ModuleName.toString moduleName
^ " = require('"
^ (importPath |> ImportPath.emit)
Expand Down
7 changes: 4 additions & 3 deletions jscomp/gentype_tests/typescript-react-example/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"extends": [
"react-app",
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"ignorePatterns": ["src/**/*.bs.js", "src/**/*.tsx", "src/MyMath.ts"]
}
"ignorePatterns": ["src/**/*.bs.js"],
"root": true
}
1 change: 1 addition & 0 deletions jscomp/gentype_tests/typescript-react-example/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ test:
npm install
npm run build
npm run tsc
npm run lint

clean:
rm -rf node_modules lib src/*.bs.js src/*.gen.tsx
Expand Down
Loading