|
21 | 21 | #include <vector> |
22 | 22 |
|
23 | 23 | using ::testing::ElementsAreArray; |
| 24 | +using ::testing::IsEmpty; |
24 | 25 |
|
25 | 26 | namespace quick_lint_js { |
26 | 27 | namespace { |
@@ -334,6 +335,22 @@ TEST_F(Test_Parse_TypeScript_Module, |
334 | 335 | "visit_end_of_module", |
335 | 336 | })); |
336 | 337 | } |
| 338 | + |
| 339 | + { |
| 340 | + Spy_Visitor p = test_parse_and_visit_statement( |
| 341 | + u8"export type {T} from 'othermod';"_sv, // |
| 342 | + u8" ^^^^ Diag_TypeScript_Type_Export_Not_Allowed_In_JavaScript"_diag, // |
| 343 | + javascript_options); |
| 344 | + EXPECT_THAT(p.visits, IsEmpty()); |
| 345 | + } |
| 346 | + |
| 347 | + { |
| 348 | + Spy_Visitor p = test_parse_and_visit_statement( |
| 349 | + u8"export type * from 'othermod';"_sv, // |
| 350 | + u8" ^^^^ Diag_TypeScript_Type_Export_Not_Allowed_In_JavaScript"_diag, // |
| 351 | + javascript_options); |
| 352 | + EXPECT_THAT(p.visits, IsEmpty()); |
| 353 | + } |
337 | 354 | } |
338 | 355 |
|
339 | 356 | TEST_F(Test_Parse_TypeScript_Module, inline_type_export) { |
@@ -409,6 +426,94 @@ TEST_F(Test_Parse_TypeScript_Module, mixed_inline_type_and_type_only_export) { |
409 | 426 | } |
410 | 427 | } |
411 | 428 |
|
| 429 | +TEST_F(Test_Parse_TypeScript_Module, export_type_from) { |
| 430 | + { |
| 431 | + Spy_Visitor p = test_parse_and_visit_statement( |
| 432 | + u8"export type * from 'other';"_sv, no_diags, typescript_options); |
| 433 | + EXPECT_THAT(p.visits, IsEmpty()); |
| 434 | + } |
| 435 | + |
| 436 | + { |
| 437 | + Spy_Visitor p = test_parse_and_visit_statement( |
| 438 | + u8"export type * as mother from 'other';"_sv, no_diags, |
| 439 | + typescript_options); |
| 440 | + EXPECT_THAT(p.visits, IsEmpty()); |
| 441 | + } |
| 442 | + |
| 443 | + { |
| 444 | + Spy_Visitor p = test_parse_and_visit_statement( |
| 445 | + u8"export type * as 'mother' from 'other';"_sv, no_diags, |
| 446 | + typescript_options); |
| 447 | + EXPECT_THAT(p.visits, IsEmpty()); |
| 448 | + } |
| 449 | + |
| 450 | + { |
| 451 | + Spy_Visitor p = test_parse_and_visit_statement( |
| 452 | + u8"export type {} from 'other';"_sv, no_diags, typescript_options); |
| 453 | + EXPECT_THAT(p.visits, IsEmpty()); |
| 454 | + } |
| 455 | + |
| 456 | + { |
| 457 | + Spy_Visitor p = test_parse_and_visit_statement( |
| 458 | + u8"export type {util1, util2, util3} from 'other';"_sv, no_diags, |
| 459 | + typescript_options); |
| 460 | + EXPECT_THAT(p.visits, IsEmpty()); |
| 461 | + } |
| 462 | + |
| 463 | + { |
| 464 | + Spy_Visitor p = test_parse_and_visit_statement( |
| 465 | + u8"export type {readFileSync as readFile} from 'fs';"_sv, no_diags, |
| 466 | + typescript_options); |
| 467 | + EXPECT_THAT(p.visits, IsEmpty()); |
| 468 | + } |
| 469 | + |
| 470 | + { |
| 471 | + Spy_Visitor p = test_parse_and_visit_statement( |
| 472 | + u8"export type {promises as default} from 'fs';"_sv, no_diags, |
| 473 | + typescript_options); |
| 474 | + EXPECT_THAT(p.visits, IsEmpty()); |
| 475 | + } |
| 476 | + |
| 477 | + for (String8 keyword : keywords) { |
| 478 | + Padded_String code( |
| 479 | + concat(u8"export type {"_sv, keyword, u8"} from 'other';"_sv)); |
| 480 | + SCOPED_TRACE(code); |
| 481 | + Spy_Visitor p = test_parse_and_visit_statement(code.string_view(), no_diags, |
| 482 | + typescript_options); |
| 483 | + EXPECT_THAT(p.visits, IsEmpty()); |
| 484 | + } |
| 485 | + |
| 486 | + { |
| 487 | + // Keywords are legal, even if Unicode-escaped. |
| 488 | + Spy_Visitor p = test_parse_and_visit_statement( |
| 489 | + u8"export type {\\u{76}ar} from 'fs';"_sv, no_diags, |
| 490 | + typescript_options); |
| 491 | + EXPECT_THAT(p.visits, IsEmpty()); |
| 492 | + } |
| 493 | + |
| 494 | + { |
| 495 | + // Keywords are legal, even if Unicode-escaped. |
| 496 | + Spy_Visitor p = test_parse_and_visit_statement( |
| 497 | + u8"export type {\\u{76}ar as \\u{69}f} from 'fs';"_sv, no_diags, |
| 498 | + typescript_options); |
| 499 | + EXPECT_THAT(p.visits, IsEmpty()); |
| 500 | + } |
| 501 | + |
| 502 | + { |
| 503 | + Spy_Visitor p = test_parse_and_visit_statement( |
| 504 | + u8"export type {'name'} from 'other';"_sv, no_diags, |
| 505 | + typescript_options); |
| 506 | + EXPECT_THAT(p.visits, IsEmpty()); |
| 507 | + } |
| 508 | + |
| 509 | + { |
| 510 | + Spy_Visitor p = test_parse_and_visit_statement( |
| 511 | + u8"export type {'name' as 'othername'} from 'other';"_sv, no_diags, |
| 512 | + typescript_options); |
| 513 | + EXPECT_THAT(p.visits, IsEmpty()); |
| 514 | + } |
| 515 | +} |
| 516 | + |
412 | 517 | TEST_F(Test_Parse_TypeScript_Module, import_require) { |
413 | 518 | { |
414 | 519 | Spy_Visitor p = test_parse_and_visit_module( |
|
0 commit comments