Skip to content
Open
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
1 change: 1 addition & 0 deletions tests/analysis_tests/tests/src/DocumentSymbol.res
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ module O = {
}

let zzz = 11
let templateString = `hello ${zzz->Int.toString}`

//^doc
12 changes: 12 additions & 0 deletions tests/analysis_tests/tests/src/expected/DocumentSymbol.res.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
DocumentSymbol src/DocumentSymbol.res
[
{
"kind": 13,
"name": "templateString",
"range": {
"end": { "character": 49, "line": 32 },
"start": { "character": 0, "line": 32 }
},
"selectionRange": {
"end": { "character": 49, "line": 32 },
"start": { "character": 0, "line": 32 }
}
},
{
"kind": 16,
"name": "zzz",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

Warning number 110
/.../fixtures/json_literal_todo_payload.res:3:13-32

1 │ /* Known bug: json literals are only meaningful in external attributes,
│ but
2 │ this is currently treated as a regular todo payload. */
3 │ let value = %todo(json`message`)
4 │

Todo found: message

This code is not implemented yet and will crash at runtime. Make sure you implement this before running the code.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* Known bug: json literals are only meaningful in external attributes, but
this is currently treated as a regular todo payload. */
let value = %todo(json`message`)
Comment thread
cknitt marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as EscapedNamesJS from './EscapedNames.res.js';

export type variant = "Illegal\"Name";
export type variant = "Illegal\"Name" | "café\npath\\name";

export type UppercaseVariant = "Illegal\"Name";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@genType
type variant = | @as("Illegal\"Name") IllegalName
type variant =
| @as("Illegal\"Name") IllegalName
| @as("café\npath\\name") Utf8

@genType
type \"UppercaseVariant" = | @as("Illegal\"Name") IllegalName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* eslint-disable */
/* tslint:disable */

import {round as roundNotChecked} from './MyMath';
import {round as roundNotChecked} from './MyM\x61th';

import {round2 as round2NotChecked} from './MyMath';

Expand All @@ -13,6 +13,10 @@ import {returnMixedArray as returnMixedArrayNotChecked} from './MyMath';

import {useColor as useColorNotChecked} from './MyMath';

import {useEscapedInlineVariant as useEscapedInlineVariantNotChecked} from './MyMath';

import {useUtf8InlineVariant as useUtf8InlineVariantNotChecked} from './MyMath';

import {higherOrder as higherOrderNotChecked} from './MyMath';

import {convertVariant as convertVariantNotChecked} from './MyMath';
Expand All @@ -21,7 +25,7 @@ import {polymorphic as polymorphicNotChecked} from './MyMath';

import {default as defaultNotChecked} from './MyMath';

// In case of type error, check the type of 'round' in 'ImportJsValue.res' and './MyMath'.
// In case of type error, check the type of 'round' in 'ImportJsValue.res' and './MyM\x61th'.
export const roundTypeChecked: (_1:number) => number = roundNotChecked as any;

// Export 'round' early to allow circular import from the '.bs.js' file.
Expand Down Expand Up @@ -51,6 +55,18 @@ export const useColorTypeChecked: (_1:color) => number = useColorNotChecked as a
// Export 'useColor' early to allow circular import from the '.bs.js' file.
export const useColor: unknown = useColorTypeChecked as (_1:color) => number as any;

// In case of type error, check the type of 'useEscapedInlineVariant' in 'ImportJsValue.res' and './MyMath'.
export const useEscapedInlineVariantTypeChecked: (_1:"Illegal\"Name") => number = useEscapedInlineVariantNotChecked as any;

// Export 'useEscapedInlineVariant' early to allow circular import from the '.bs.js' file.
export const useEscapedInlineVariant: unknown = useEscapedInlineVariantTypeChecked as (_1:"Illegal\"Name") => number as any;

// In case of type error, check the type of 'useUtf8InlineVariant' in 'ImportJsValue.res' and './MyMath'.
export const useUtf8InlineVariantTypeChecked: (_1:"café\npath\\name") => number = useUtf8InlineVariantNotChecked as any;

// Export 'useUtf8InlineVariant' early to allow circular import from the '.bs.js' file.
export const useUtf8InlineVariant: unknown = useUtf8InlineVariantTypeChecked as (_1:"café\npath\\name") => number as any;

// In case of type error, check the type of 'higherOrder' in 'ImportJsValue.res' and './MyMath'.
export const higherOrderTypeChecked: (_1:((_1:number, _2:number) => number)) => number = higherOrderNotChecked as any;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@ocaml.doc("
* Wrap JS values to be used from Reason
")
@genType.import("./MyMath")
@genType.import(`./MyM\x61th`)
external /* This is the module to import from. */
/* Name and type of the JS value to bind to. */
round: float => float = "round"
Expand Down Expand Up @@ -57,6 +57,14 @@ type stringFunction

@genType.import("./MyMath") external useColor: color => int = "useColor"

@genType.import("./MyMath")
external useEscapedInlineVariant: @string [@as("Illegal\"Name") #illegalName] => int =
"useEscapedInlineVariant"

@genType.import("./MyMath")
external useUtf8InlineVariant: @string [@as("café\npath\\name") #utf8] => int =
"useUtf8InlineVariant"

@genType.import("./MyMath") external higherOrder: ((int, int) => int) => int = "higherOrder"

@genType let returnedFromHigherOrder = higherOrder(\"+")
Expand Down

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

4 changes: 4 additions & 0 deletions tests/gentype_tests/typescript-react-example/src/MyMath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export type stringFunction = (_: string) => string;

export const useColor = (_x: "tomato" | "gray"): number => 0;

export const useEscapedInlineVariant = (_x: 'Illegal"Name'): number => 0;

export const useUtf8InlineVariant = (_x: "café\npath\\name"): number => 0;

export const higherOrder = (foo: (_1: number, _2: number) => number) =>
foo(3, 4);

Expand Down
23 changes: 23 additions & 0 deletions tests/ounit_tests/ounit_ast_mapper0_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,27 @@ let test_fun_param_attrs_roundtrip_through_ast0 _ =
(attr_names p_attrs)
| _ -> assert_failure "Expected a function after ast0 roundtrip"

let test_error_extension_encoded_strings _ =
let encoded_string value =
Ast_helper.Str.eval ~loc
(Ast_helper.Exp.constant ~loc
(Parsetree.Pconst_string (value, Some "js")))
in
let extension =
( Location.mknoloc "error",
Parsetree.PStr
[
encoded_string {|plain\nmessage|};
encoded_string {|highlighted\nmessage|};
] )
in
let error = Builtin_attributes.error_of_extension extension in
(* Known bug: these are encoded string bodies, but error extensions expose
their source spelling instead of their decoded semantic values. *)
OUnit.assert_equal ~printer:(Printf.sprintf "%S") {|plain\nmessage|} error.msg;
OUnit.assert_equal ~printer:(Printf.sprintf "%S") {|highlighted\nmessage|}
error.if_highlight

let suites =
__FILE__
>::: [
Expand All @@ -243,4 +264,6 @@ let suites =
>:: test_value_constraint_roundtrips_through_ast0;
"function_cases_desugar_to_fun_match"
>:: test_function_cases_desugar_to_fun_match;
"error_extensions_expose_encoded_strings"
>:: test_error_extension_encoded_strings;
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

Syntax error!
syntax_tests/data/parsing/errors/scanner/invalidSurrogatePair.res:3:35-40

1 │ /* Known bug: this valid JavaScript surrogate pair is rejected as two in
│ valid
2 │ standalone surrogate escapes. */
3 │ let validPairCurrentlyRejected = "\uD83D\uDE00"
4 │
5 │ let malformed = "\uD83D\uZZZZ"

escape sequence is invalid unicode code point


Syntax error!
syntax_tests/data/parsing/errors/scanner/invalidSurrogatePair.res:3:41-46

1 │ /* Known bug: this valid JavaScript surrogate pair is rejected as two in
│ valid
2 │ standalone surrogate escapes. */
3 │ let validPairCurrentlyRejected = "\uD83D\uDE00"
4 │
5 │ let malformed = "\uD83D\uZZZZ"

escape sequence is invalid unicode code point


Syntax error!
syntax_tests/data/parsing/errors/scanner/invalidSurrogatePair.res:5:18-23

3 │ let validPairCurrentlyRejected = "\uD83D\uDE00"
4 │
5 │ let malformed = "\uD83D\uZZZZ"
6 │ let after = 1
7 │

escape sequence is invalid unicode code point


Syntax error!
syntax_tests/data/parsing/errors/scanner/invalidSurrogatePair.res:5:24-25

3 │ let validPairCurrentlyRejected = "\uD83D\uDE00"
4 │
5 │ let malformed = "\uD83D\uZZZZ"
6 │ let after = 1
7 │

unknown escape sequence

let validPairCurrentlyRejected = {js|\uD83D\uDE00|js}
let malformed = {js|\uD83D\uZZZZ|js}
let after = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* Known bug: this valid JavaScript surrogate pair is rejected as two invalid
standalone surrogate escapes. */
let validPairCurrentlyRejected = "\uD83D\uDE00"

let malformed = "\uD83D\uZZZZ"
let after = 1
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
@@jsxConfig({version: 4})
@@jsxConfig({version: 4, module_: `Pre\x61ct`})

module V4A = {
@res.jsxComponentProps
type props<'msg> = {
msg: 'msg,
}

let make = ({msg, _}: props<_>): React.element => {
ReactDOM.jsx("div", {children: ?ReactDOM.someElement({msg->React.string})})
let make = ({msg, _}: props<_>): Pre\x61ct.element => {
Pre\x61ct.Elements.jsx("div", {children: ?Pre\x61ct.Elements.someElement({msg->React.string})})
}
let make = React.component({
let make = Pre\x61ct.component({
let \"FileLevelConfig$V4A" = (props: props<_>) => make(props)

\"FileLevelConfig$V4A"
Expand Down
2 changes: 1 addition & 1 deletion tests/syntax_tests/data/ppx/react/fileLevelConfig.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@@jsxConfig({version: 4})
@@jsxConfig({version: 4, module_: `Pre\x61ct`})

module V4A = {
@react.component
Expand Down
3 changes: 3 additions & 0 deletions tests/tests/src/AsInUncurriedExternals.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ function shouldNotFail(objectMode, name) {

let x = somescope.somefn({foo:true});

let y = somescope.stringfn(`\x61\u0062`);

export {
mo,
options,
shouldNotFail,
x,
y,
}
/* x Not a pure module */
5 changes: 5 additions & 0 deletions tests/tests/src/AsInUncurriedExternals.res
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ let shouldNotFail: (~objectMode: _, ~name: string) => int = (~objectMode, ~name)
external constantArgOnly: @as(json`{foo:true}`) _ => string = "somefn"

let x = constantArgOnly()

@scope("somescope")
external semanticStringArg: @as(`\x61\u0062`) _ => string = "stringfn"

let y = semanticStringArg()
4 changes: 2 additions & 2 deletions tests/tests/src/ImportAttributes.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Generated by ReScript, PLEASE EDIT WITH CARE

import * as MyCssCss from "./myCss.css" with {"type": "css", "some-identifier": "yep"};
import MyJsonJson from "./myJson.json" with {"type": "json", "some-identifier": "yep"};
import * as MyCssCss from "./myCss.css" with {"type": "c\\x73s", "some-identifier": "y\\x65p"};
import MyJsonJson from "./myJson.json" with {"type": "j\\x73on", "some-identifier": "y\\x65p"};

let myJson = MyJsonJson;

Expand Down
4 changes: 2 additions & 2 deletions tests/tests/src/ImportAttributes.res
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@module({from: "./myJson.json", with: {type_: "json", \"some-identifier": "yep"}})
@module({from: `./myJson.json`, with: {type_: `j\x73on`, \"some-identifier": `y\x65p`}})
external myJson: JSON.t = "default"

Console.log(myJson)

@module({from: "./myCss.css", with: {type_: "css", \"some-identifier": "yep"}})
@module({from: `./myCss.css`, with: {type_: `c\x73s`, \"some-identifier": `y\x65p`}})
external buttonCss: string = "button"

Console.log(buttonCss)
26 changes: 15 additions & 11 deletions tests/tests/src/gpr_3142_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import * as Mocha from "mocha";
import * as Test_utils from "./test_utils.mjs";

let _map = {"a":"x","u":"hi","b":"你","c":"我"};
let _map = {"a":"x","u":"hi","b":"你","c":"我","d":"\x64","e":"\u0065"};

let _revMap = {"x":"a","hi":"u","你":"b","我":"c"};
let _revMap = {"x":"a","hi":"u","你":"b","我":"c","\x64":"d","\u0065":"e"};

function tToJs(param) {
return _map[param];
Expand All @@ -17,15 +17,19 @@ function tFromJs(param) {

Mocha.describe("Gpr_3142_test", () => {
Mocha.test("jsConverter derivation", () => {
Test_utils.eq("File \"gpr_3142_test.res\", line 18, characters 7-14", tToJs("a"), "x");
Test_utils.eq("File \"gpr_3142_test.res\", line 19, characters 7-14", tToJs("u"), "hi");
Test_utils.eq("File \"gpr_3142_test.res\", line 20, characters 7-14", tToJs("b"), `你`);
Test_utils.eq("File \"gpr_3142_test.res\", line 21, characters 7-14", tToJs("c"), `我`);
Test_utils.eq("File \"gpr_3142_test.res\", line 23, characters 7-14", tFromJs("x"), "a");
Test_utils.eq("File \"gpr_3142_test.res\", line 24, characters 7-14", tFromJs("hi"), "u");
Test_utils.eq("File \"gpr_3142_test.res\", line 25, characters 7-14", tFromJs(`你`), "b");
Test_utils.eq("File \"gpr_3142_test.res\", line 26, characters 7-14", tFromJs(`我`), "c");
Test_utils.eq("File \"gpr_3142_test.res\", line 27, characters 7-14", tFromJs("xx"), undefined);
Test_utils.eq("File \"gpr_3142_test.res\", line 20, characters 7-14", tToJs("a"), "x");
Test_utils.eq("File \"gpr_3142_test.res\", line 21, characters 7-14", tToJs("u"), "hi");
Test_utils.eq("File \"gpr_3142_test.res\", line 22, characters 7-14", tToJs("b"), `你`);
Test_utils.eq("File \"gpr_3142_test.res\", line 23, characters 7-14", tToJs("c"), `我`);
Test_utils.eq("File \"gpr_3142_test.res\", line 24, characters 7-14", tToJs("d"), "d");
Test_utils.eq("File \"gpr_3142_test.res\", line 25, characters 7-14", tToJs("e"), "e");
Test_utils.eq("File \"gpr_3142_test.res\", line 27, characters 7-14", tFromJs("x"), "a");
Test_utils.eq("File \"gpr_3142_test.res\", line 28, characters 7-14", tFromJs("hi"), "u");
Test_utils.eq("File \"gpr_3142_test.res\", line 29, characters 7-14", tFromJs(`你`), "b");
Test_utils.eq("File \"gpr_3142_test.res\", line 30, characters 7-14", tFromJs(`我`), "c");
Test_utils.eq("File \"gpr_3142_test.res\", line 31, characters 7-14", tFromJs("d"), "d");
Test_utils.eq("File \"gpr_3142_test.res\", line 32, characters 7-14", tFromJs("e"), "e");
Test_utils.eq("File \"gpr_3142_test.res\", line 33, characters 7-14", tFromJs("xx"), undefined);
});
});

Expand Down
Loading
Loading