@@ -1190,6 +1190,33 @@ describe("printer", function () {
1190
1190
assert . strictEqual ( pretty , code ) ;
1191
1191
} ) ;
1192
1192
1193
+ it ( "prints 'definite' ClassProperty correctly" , function ( ) {
1194
+ const code = [ "class A {" , " foo!: string;" , "}" ] . join ( eol ) ;
1195
+
1196
+ const ast = b . program ( [
1197
+ b . classDeclaration (
1198
+ b . identifier ( "A" ) ,
1199
+ b . classBody ( [
1200
+ Object . assign (
1201
+ b . classProperty (
1202
+ b . identifier ( "foo" ) ,
1203
+ null ,
1204
+ b . typeAnnotation ( b . stringTypeAnnotation ( ) ) ,
1205
+ ) ,
1206
+ { definite : true } ,
1207
+ ) ,
1208
+ ] ) ,
1209
+ ) ,
1210
+ ] ) ;
1211
+
1212
+ const printer = new Printer ( {
1213
+ tabWidth : 2 ,
1214
+ } ) ;
1215
+
1216
+ const pretty = printer . printGenerically ( ast ) . code ;
1217
+ assert . strictEqual ( pretty , code ) ;
1218
+ } ) ;
1219
+
1193
1220
it ( "prints static ClassProperty correctly" , function ( ) {
1194
1221
const code = [ "class A {" , " static foo = Bar;" , "}" ] . join ( eol ) ;
1195
1222
@@ -1671,12 +1698,8 @@ describe("printer", function () {
1671
1698
1672
1699
it ( "prints chained expression elements" , function ( ) {
1673
1700
const node = b . chainExpression (
1674
- b . memberExpression (
1675
- b . identifier ( "foo" ) ,
1676
- b . identifier ( "bar" ) ,
1677
- false
1678
- ) ,
1679
- )
1701
+ b . memberExpression ( b . identifier ( "foo" ) , b . identifier ( "bar" ) , false ) ,
1702
+ ) ;
1680
1703
1681
1704
assert . strictEqual ( recast . print ( node ) . code , "foo.bar" ) ;
1682
1705
} ) ;
@@ -1687,9 +1710,9 @@ describe("printer", function () {
1687
1710
b . identifier ( "foo" ) ,
1688
1711
b . identifier ( "bar" ) ,
1689
1712
false ,
1690
- true
1713
+ true ,
1691
1714
) ,
1692
- )
1715
+ ) ;
1693
1716
1694
1717
assert . strictEqual ( recast . print ( node ) . code , "foo?.bar" ) ;
1695
1718
} ) ;
@@ -2192,23 +2215,29 @@ describe("printer", function () {
2192
2215
} ) ;
2193
2216
2194
2217
const emptyBlockReprinted = printer . print ( ast ) . code ;
2195
- assert . strictEqual ( emptyBlockReprinted , [
2196
- "class A {" ,
2197
- " static a = 1;" ,
2198
- " static #b = 2;" ,
2199
- "" , // Empty line preserved because of conservative printer.print reprinting.
2200
- " static {}" ,
2201
- "}" ,
2202
- ] . join ( eol ) ) ;
2218
+ assert . strictEqual (
2219
+ emptyBlockReprinted ,
2220
+ [
2221
+ "class A {" ,
2222
+ " static a = 1;" ,
2223
+ " static #b = 2;" ,
2224
+ "" , // Empty line preserved because of conservative printer.print reprinting.
2225
+ " static {}" ,
2226
+ "}" ,
2227
+ ] . join ( eol ) ,
2228
+ ) ;
2203
2229
2204
2230
const emptyBlockPrettyPrinted = printer . printGenerically ( ast ) . code ;
2205
- assert . strictEqual ( emptyBlockPrettyPrinted , [
2206
- "class A {" ,
2207
- " static a = 1;" ,
2208
- " static #b = 2;" ,
2209
- " static {}" ,
2210
- "}" ,
2211
- ] . join ( eol ) ) ;
2231
+ assert . strictEqual (
2232
+ emptyBlockPrettyPrinted ,
2233
+ [
2234
+ "class A {" ,
2235
+ " static a = 1;" ,
2236
+ " static #b = 2;" ,
2237
+ " static {}" ,
2238
+ "}" ,
2239
+ ] . join ( eol ) ,
2240
+ ) ;
2212
2241
} ) ;
2213
2242
2214
2243
it ( "can pretty-print ImportAttribute syntax" , function ( ) {
@@ -2223,10 +2252,10 @@ describe("printer", function () {
2223
2252
'import * as noAssertions from "./module";' ,
2224
2253
'import * as emptyAssert from "./module";' ,
2225
2254
'import json from "./module" assert { type: "json" };' ,
2226
- '' ,
2255
+ "" ,
2227
2256
'import * as ns from "./module" assert {' ,
2228
2257
' type: "reallyLongStringLiteralThatShouldTriggerReflowOntoMultipleLines"' ,
2229
- '};' ,
2258
+ "};" ,
2230
2259
] . join ( eol ) ;
2231
2260
2232
2261
const printer = new Printer ( {
@@ -2254,12 +2283,15 @@ describe("printer", function () {
2254
2283
} ) ;
2255
2284
2256
2285
const reprinted = printer . print ( ast ) . code ;
2257
- assert . strictEqual ( reprinted , [
2258
- 'import * as noAssertions from "./module";' ,
2259
- 'import * as emptyAssert from "./module" assert {};' ,
2260
- 'import json from "./module" assert { type: "json" };' ,
2261
- 'import * as ns from "./module" assert { type: "shorter" }' ,
2262
- ] . join ( eol ) ) ;
2286
+ assert . strictEqual (
2287
+ reprinted ,
2288
+ [
2289
+ 'import * as noAssertions from "./module";' ,
2290
+ 'import * as emptyAssert from "./module" assert {};' ,
2291
+ 'import json from "./module" assert { type: "json" };' ,
2292
+ 'import * as ns from "./module" assert { type: "shorter" }' ,
2293
+ ] . join ( eol ) ,
2294
+ ) ;
2263
2295
} ) ;
2264
2296
2265
2297
it ( "can pretty-print RecordExpression syntax" , function ( ) {
@@ -2316,8 +2348,8 @@ describe("printer", function () {
2316
2348
it ( "can pretty-print ModuleExpression syntax" , function ( ) {
2317
2349
const code = [
2318
2350
'import { log } from "logger";' ,
2319
- ' export const url = import.meta.url;' ,
2320
- ' log(url);' ,
2351
+ " export const url = import.meta.url;" ,
2352
+ " log(url);" ,
2321
2353
] . join ( eol ) ;
2322
2354
2323
2355
const ast = parse ( code , {
@@ -2332,13 +2364,12 @@ describe("printer", function () {
2332
2364
const pretty = printer . printGenerically ( ast ) . code ;
2333
2365
assert . strictEqual ( pretty , code ) ;
2334
2366
2335
- const reprinted = printer . print (
2336
- b . moduleExpression ( ast . program )
2337
- ) . code ;
2338
- assert . strictEqual ( reprinted , [
2339
- "module {" ,
2340
- ...code . split ( eol ) . map ( line => " " + line ) ,
2341
- "}" ,
2342
- ] . join ( eol ) ) ;
2367
+ const reprinted = printer . print ( b . moduleExpression ( ast . program ) ) . code ;
2368
+ assert . strictEqual (
2369
+ reprinted ,
2370
+ [ "module {" , ...code . split ( eol ) . map ( ( line ) => " " + line ) , "}" ] . join (
2371
+ eol ,
2372
+ ) ,
2373
+ ) ;
2343
2374
} ) ;
2344
2375
} ) ;
0 commit comments