$30 off During Our Annual Pro Sale. View Details »

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
PRO

September 25, 2023
Tweet

More Decks by Yosuke Furukawa

Other Decks in Programming

Transcript

  1. TC39 x JSConf.jp


    Panel Discussion
    2023/09/25 @ South Tower Tokyo

    View Slide

  2. We will talk about JS
    weakpoints, next features,
    and so on.

    View Slide

  3. First, take a look at our
    survey.

    View Slide

  4. Excited proposals

    View Slide

  5. Which proposal are you
    most excited? / Ͳͷϓϩϙ
    ʔβϧʹظ଴Λ͍ͯ͠·͢
    ͔ʁ

    View Slide

  6. Most exciting proposals
    • Temporal x 12


    • Pipeline operator x 10


    • Pattern Matching x 7


    • Record and Tuple x 5


    • JSON Modules x 3

    View Slide

  7. 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]

    View Slide

  8. 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);

    View Slide

  9. 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();
    }

    View Slide

  10. 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

    View Slide

  11. JSON Modules
    // Stage 3
    import foo from "foo.json" with { type: "json" };

    View Slide

  12. Which proposals are
    exciting? (TC39 team?)
    • Iterator helpers


    • Pattern matching, modules declarations, deferred
    imports, compartments


    • temporal


    • Array.fromAsync


    • type annotation

    View Slide

  13. Weak points

    View Slide

  14. Do you have current
    JavaScript weak points?
    and what are the weak
    points? / ͲΜͳ఺͕
    JavaScriptͷऑ఺ͩͱࢥ͍·
    ͔͢ʁ

    View Slide

  15. 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.

    View Slide

  16. 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.



    View Slide

  17. JavaScript weak points
    • ESM and CJS separate the JS world.


    • ESMͱCommonJSͰ΍͸Γੈք͕෼அ͞Εͯ
    ͠·͏ॴ



    View Slide

  18. 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.

    View Slide

  19. 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!!

    View Slide

  20. 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.

    View Slide

  21. 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.

    View Slide

  22. Discussion:


    (Yosuke's talk)

    View Slide

  23. 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.

    View Slide

  24. 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

    View Slide

  25. 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).

    View Slide

  26. 😇 My Opinion:


    This is nobody's fault.


    Future prediction is hard.

    View Slide