Rollup-plugin-typescript2: فشل تسلسل اختياري مع "target": "esnext" في tsconfig

تم إنشاؤها على ١٥ نوفمبر ٢٠١٩  ·  7تعليقات  ·  مصدر: ezolenko/rollup-plugin-typescript2

ماذا يحدث ولماذا هو خطأ

https://github.com/brandon-leapyear/rollup-optional-chaining-repro

منسوخ من README:

yarn rollup -c

قم بإلغاء التعليق عن السطر "target": "esnext" في tsconfig.json لإظهار الخطأ:

index.ts: (3:57)
[!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
index.ts (3:57)
1: import React from 'react'
2: 
3: const a: { b?: string } = {}
                               ^
4: 
5: export default () => <span>{a?.b}</span>
Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
    at error (/Users/bchinn/Desktop/rollup-example/node_modules/rollup/dist/rollup.js:5351:30)
    at Module.error (/Users/bchinn/Desktop/rollup-example/node_modules/rollup/dist/rollup.js:9643:9)
    at tryParse (/Users/bchinn/Desktop/rollup-example/node_modules/rollup/dist/rollup.js:9552:16)
    at Module.setSource (/Users/bchinn/Desktop/rollup-example/node_modules/rollup/dist/rollup.js:9868:33)
    at /Users/bchinn/Desktop/rollup-example/node_modules/rollup/dist/rollup.js:12148:20
    at async Promise.all (index 0)
    at async Promise.all (index 0)
    at async Promise.all (index 0)

يبدو أنه خطأ في rollup-plugin-typescript2 لأنه مع "target": "esnext"
بدون تعليق ، لا يزال yarn tsc --noEmit يعمل (على سبيل المثال ، يُعَرِّف كتاب الطباعة بشكل جيد).

بيئة

لا ينبغي أن تكون ذات صلة

إصدارات

  • مطبوعة: الأحدث
  • تراكمي: الأحدث
  • rollup-plugin-typescript2: الأحدث

rollup.config.js

import typescript from 'rollup-plugin-typescript2'

export default {
  input: 'index.ts',
  output: [
    {
      file: 'dist/index.js',
      format: 'es',
    },
  ],
  plugins: [
    typescript({
      typescript: require('typescript'),
    })
  ],
}

tsconfig.json

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "jsx": "react",

    // Uncomment to break:
    // "target": "esnext",
  }
}

package.json

{
    "name": "rollup-optional-chaining-repro",
    "version": "0.0.1",
    "private": true,
    "devDependencies": {
        "rollup": "^1.27.0",
        "rollup-plugin-typescript2": "^0.25.2"
    },
    "dependencies": {
        "typescript": "^3.7.2"
    }
}

إخراج البرنامج المساعد مع الإسهاب 3

plugin-debug.txt

ال 7 كومينتر

نسخ الكتابة من a?.b إلى (_a = a) === null || _a === void 0 ? void 0 : _a.b عند استخدام es2015 (افتراضي).

إنها تنقل a?.b إلى a?.b عند استخدام esnext . أعتقد أن هذه ميزة JS أصلية في esnext ،

الخطأ الذي تراه هو فشل مجموعة التحديثات في تحليل هذا. (لست متأكدًا مما إذا كان من المفترض أن يدعمها أم لا).

يمكنك التحقق من خلال تشغيل tsc ، وجعله يرسل index.js ثم استخدام ملف js كمدخل تراكمي. يجب أن تحصل على نفس الخطأ.

لا أعتقد أن هذا هو الحال. بعد إلغاء التعليق "target": "esnext" وتشغيل yarn tsc index.ts ، يحتوي index.js على:

var _a;
var a = {};
console.log((_a = a) === null || _a === void 0 ? void 0 : _a.b);

(لا يزال يخفق yarn rollup -c )

حسنًا ، لم يحدث لي ، فهمت

const a = {};
console.log(a?.b);

تحقق مما إذا كان الإصدار المطبوع عليه هو ما تعتقد أنه هو (ربما يطلق الغزل إصدارًا عالميًا؟):

.\node_modules\.bin\tsc --version
Version 3.7.2

لدي نفس المشكلة مع الهدف "esnext" والتسلسل الاختياري. هل هناك حل حتى الان؟ كل شيء يجمع مع tsc

@ dagda1 ، هذا ليس خطأ - هذا مطبعي يولد كودًا صحيحًا (لهدف esnext) لا يمكن أن تستهلكه مجموعة التحديثات تمامًا. يمكنك إضافة ملحق babel إلى السلسلة إذا كان يجب أن يكون لديك esnext.

ezolenko هل لا تزال هذه هي الحالة التي تتطلب إضافات babel الإضافية

بقدر ما أعرف نعم ، يمكنك تجربة أحدث إصدار من مجموعة التحديثات ومعرفة ما إذا كان يعمل (إذا تم إصلاح شيء ما ، فسيكون في جانب التجميع أو في أحد تبعياته).

هل كانت هذه الصفحة مفيدة؟
0 / 5 - 0 التقييمات