Upgrade to Pro — share decks privately, control downloads, hide ads and more …

tc39 x jsconf.jp Panel Discussion

tc39 x jsconf.jp Panel Discussion

2023/09/25 @ Recruit South Tower
TC39 x JSConf.jp Collaboration Event

Yosuke Furukawa

September 25, 2023
Tweet

More Decks by Yosuke Furukawa

Other Decks in Programming

Transcript

  1. Most exciting proposals • Temporal x 12 • Pipeline operator

    x 10 • Pattern Matching x 7 • Record and Tuple x 5 • JSON Modules x 3
  2. Temporal // Stage 3 const zonedDateTime = Temporal.ZonedDateTime.from({ timeZone: 'America/Los_Angeles',

    year: 1995, month: 12, day: 7, hour: 3, minute: 24, second: 30, millisecond: 0, microsecond: 3, nanosecond: 500 }); // => 1995-12-07T03:24:30.0000035-08:00[America/Los_Angeles]
  3. Pipeline operator // Stage 2 // Previous const json =

    await npmFetch.json(npa(pkgs[0]).escapedName, opts); // With pipes const json = pkgs[0] |> npa(%).escapedName |> await npmFetch.json(%, opts);
  4. Pattern Matching // Stage 1 match (res) { when ({

    status: 200, body, ...rest }): handleData(body, rest) when ({ status, destination: url }) if (300 <= status && status < 400): handleRedirect(url) when ({ status: 500 }) if (!this.hasRetried): do { retry(req); this.hasRetried = true; } default: throwSomething(); }
  5. Record and Tuple // Stage 2 const record = #{

    prop: 1 }; const tuple = #[1, 2, 3]; Record.isRecord(record); // true Record.isRecord({ prop: 1 }); // false // Equality #{ a: 1 } === #{ a:1 } // true #[1] === #[1] // true
  6. Which proposals are exciting? (TC39 team?) • Iterator helpers •

    Pattern matching, modules declarations, deferred imports, compartments • temporal • Array.fromAsync • type annotation
  7. Do you have current JavaScript weak points? and what are

    the weak points? / ͲΜͳ఺͕ JavaScriptͷऑ఺ͩͱࢥ͍· ͔͢ʁ
  8. JavaScript weak points • ݹ͍ػೳͱͷޓ׵ੑΛ࣋ͨͳ͍ͱ͍͚ͳ͍఺ɻ • JS needs to have

    an interoperability for legacy features. • This is not weak, strong point. • JS survives 20 years. • Backword compats are really important. • Some aspects of JS make it harder, such as being able to modify prototypes • To keep compatibility is needed. documentation is also important.
  9. JavaScript weak points • Some parts are scattered in various

    specs (e.g. ECMA262 does not have Cancellation. It's relying on DOM AbortController) • ECMA262 ͚ͩ͡Όͳͯ͘ɺଞͷ࢓༷΋ݟ͓͔ͯͳ͍ͱ͍͚ͳ͍ͱ͜Ζ ʢྫ͑͹ɺΩϟϯηϧ͸DOM AbortController ͱ͔ݟͯͳ͍ͱ͍͚ͳ ͍ʣ • Cancellation is misunderstandable... it is not ECMA262 spec. • JS is just the language, it is not runtime environment. some other langs have similar architecture. •
  10. JavaScript weak points • ESM and CJS separate the JS

    world. • ESMͱCommonJSͰ΍͸Γੈք͕෼அ͞Εͯ ͠·͏ॴ •
  11. JavaScript weak points • Immutability is weaker than other langs

    • ෆมΛఏڙ͢Δػೳ͕ଞͷݴޠʹൺ΂ͯऑ͍ࣄ • Most js objects are mutable, so it is hard. • Object.freeze / seal are pragmatic... • Haskell is ever thing is immutable, python, c++, Java are not so immutable. It depends on design? • TS is not so immutable either.
  12. JavaScript weak points • ະఆٛϝϯόΞΫηε΁ݫີͳ੍ޚ͕Ͱ͖ͣ unde fi ned ͕ޙͰൃ֮͢Δ఺ɻ •

    JS developers could not handle unde fi ned property access and fi nd these faults at production. • TypeScript will help you!! • Optional chaining ?. will help you!!
  13. JavaScript weak points • Coercing Things • (NaN Λ 0

    ͱͯ͠ѻͬͨΓ string ౉͞ͳ͖Ό͍͚ ͳ͍ͱ͜Ζʹ number ౉ͨ͠Βউखʹcastͨ͠Γ) • New APIs should not handle these unpredictable behaviour • Throw errors if the types are invalid.
  14. JavaScript weak points • Prototype Pollution • ϓϩτλΠϓԚછͳΜͱ͔ͳΒΜʁ • 1.

    locked down (built-in prototype is frozen, global object is also freezed) • 2. realm proposal (create new environment / realm, prototype polluted in the environment, but it is not affected all world. shadow realms are stage3, ) • node vm module does not solve security problems.
  15. ESM status • TypeScript con fi g `module` props have

    many options like es2022, nodenext, bundler, etc. • this prop nightmare is introduced by Node.js CJS / ESM options. • Node.js has CJS / ESM interop feature. • Historically, CJS is needed in Node.js. • ESM was declared in 2015. • Node.js core committer thought 2 specs would cause migration issues. • So, Node.js implemented CJS / ESM interops using the fi le extension and the package.json `type` fi eld.
  16. ESM status • Spec difference: • ESM and CJS are

    totally different. • ESM: async load / CJS: sync load • ESM: static / CJS: dynamic • ESM: pass by reference / CJS: pass by value
  17. ESM status • My opinion: • TypeScript developers feel Node.js

    brings ESM/CJS nightmare. • Node.js developers feel if CJS/ESM interop has never been implemented, migration nightmare will start. • I guess TC39 people think module system is required and it would be better to be browser friendly (CJS is not ideal it is for Node.js / Server-side).