Skip to content

swc explicitResourceManagement SuppressedError implement does not obey spec #8853

@loynoir

Description

@loynoir

Describe the bug

swc explicitResourceManagement SuppressedError implement does not obey spec.

swc runtime output is different from tsc runtime output.

Input code

import { deepStrictEqual } from 'node:assert'
import process from 'node:process'

let i = 0
let err: any
try {
  await using _x1 = {
    async [Symbol.asyncDispose]() {
      throw [1, ++i]
    }
  }

  await using _x2 = {
    async [Symbol.asyncDispose]() {
      throw [2, ++i]
    }
  }

  await using _x3 = {
    async [Symbol.asyncDispose]() {
      throw [3, ++i]
    }
  }

  await using _x4 = {
    async [Symbol.asyncDispose]() {
      throw [4, ++i]
    }
  }

  throw [5, ++i]
} catch (e) {
  err = e
}

if (process.env['REPRODUCE_SWC_BUG'] === undefined) {
  deepStrictEqual(err.error, [1, 5])
  deepStrictEqual(err.suppressed.error, [2, 4])
  deepStrictEqual(err.suppressed.suppressed.error, [3, 3])
  deepStrictEqual(err.suppressed.suppressed.suppressed.error, [4, 2])
  deepStrictEqual(err.suppressed.suppressed.suppressed.suppressed, [5, 1])
} else {
  deepStrictEqual(err.suppressed, [1, 5])
  deepStrictEqual(err.error.suppressed, [2, 4])
  deepStrictEqual(err.error.error.suppressed, [3, 3])
  deepStrictEqual(err.error.error.error.suppressed, [4, 2])
  deepStrictEqual(err.error.error.error.error, [5, 1])
}

Config

{
    "$schema": "https://json.schemastore.org/swcrc",
    "jsc": {
        "parser": {
            "syntax": "typescript",
            "explicitResourceManagement": true,
        },
        "target": "es2022",
        "loose": false,
        "minify": {
            "compress": false,
            "mangle": false
        }
    },
    "module": {
        "type": "es6"
    },
    "minify": false,
    "isModule": true
}

Playground link (or link to the minimal reproduction)

#8853

SWC Info output

No response

Expected behavior

  • If tsc is correct, expect same output as tsc.

Actual behavior

$ yarn tsc --build
...
$ yarn swc ./reproduce.mts -o reproduce/reproduce.swc.mjs
...
$ node ./reproduce/reproduce.tsc.mjs && REPRODUCE_SWC_BUG=1 node ./reproduce/reproduce.swc.mjs && echo OK
OK

Version

0.3.12

Additional context

@swc/cli: 0.3.12
@swc/core: 1.4.13

Downstream

denoland/deno#23249

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions