Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement first class mixins #2073

Merged
merged 36 commits into from Oct 5, 2023
Merged

Conversation

connorskees
Copy link
Contributor

@connorskees connorskees commented Aug 25, 2023

Tracking issue: sass/sass#626
Protobuf changes: sass/sass#3674
Spec tests: sass/sass-spec#1933
Embedded host: sass/embedded-host-node#253

Closes #2046

@connorskees connorskees marked this pull request as ready for review August 26, 2023 04:07
lib/src/callable/built_in.dart Outdated Show resolved Hide resolved
lib/src/functions/meta.dart Outdated Show resolved Hide resolved
@jathak jathak requested a review from nex3 August 28, 2023 20:47
@connorskees
Copy link
Contributor Author

I'm not able to reproduce the CI build failures locally. I assume it's to do with missing auto-generated (and gitignored) files that I have locally but which aren't created during the CI run. Is there something I'm missing updating for the embedded protocol files?

@ntkme
Copy link
Contributor

ntkme commented Aug 29, 2023

@connorskees If you are making changes to the protobuf definition, you need to submit a PR for https://github.com/sass/sass, and link the PR in the description of this PR.

@connorskees
Copy link
Contributor Author

I've reverted the embedded protocol changes for now as adding the protobuf changes to sass/sass and linking the issues didn't seem to resolve the build failures.

@nex3
Copy link
Contributor

nex3 commented Sep 6, 2023

It looks like the CI is picking up the protocol buffer definition changes (at least now), so you may want to roll forward that patch.

lib/src/callable/built_in.dart Outdated Show resolved Hide resolved
lib/src/functions/meta.dart Outdated Show resolved Hide resolved
lib/src/value.dart Outdated Show resolved Hide resolved
lib/src/visitor/async_evaluate.dart Outdated Show resolved Hide resolved
lib/src/visitor/async_evaluate.dart Show resolved Hide resolved
lib/src/visitor/async_evaluate.dart Outdated Show resolved Hide resolved
lib/src/visitor/async_evaluate.dart Outdated Show resolved Hide resolved
lib/src/embedded/mixin_registry.dart Outdated Show resolved Hide resolved
lib/src/value/mixin.dart Show resolved Hide resolved
lib/src/visitor/async_evaluate.dart Show resolved Hide resolved
lib/src/visitor/async_evaluate.dart Outdated Show resolved Hide resolved
lib/src/functions/meta.dart Outdated Show resolved Hide resolved
lib/src/visitor/async_evaluate.dart Outdated Show resolved Hide resolved
lib/src/callable/async_built_in.dart Outdated Show resolved Hide resolved
lib/src/visitor/async_evaluate.dart Outdated Show resolved Hide resolved
lib/src/visitor/async_evaluate.dart Outdated Show resolved Hide resolved
lib/src/embedded/opaque_registry.dart Outdated Show resolved Hide resolved
lib/src/embedded/opaque_registry.dart Outdated Show resolved Hide resolved
lib/src/value/mixin.dart Outdated Show resolved Hide resolved
lib/src/visitor/async_evaluate.dart Outdated Show resolved Hide resolved
@connorskees
Copy link
Contributor Author

Do I need to link to the embedded host PR in this PR description?

@nex3
Copy link
Contributor

nex3 commented Oct 3, 2023

Yes, you do.

@connorskees
Copy link
Contributor Author

Updated.

@ntkme
Copy link
Contributor

ntkme commented Oct 3, 2023

Updated.

You will also need to push a different commit in order for CI to get the updated PR description. E.g. an empty created by git commit --allow-empty would work.


/// The JavaScript `SassMixin` class.
final JSClass mixinClass = () {
var jsClass = createJSClass('sass.SassMixin', () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it is related to the browser failure, but I think the argument is missing Object self here when looking at all other values.

@connorskees
Copy link
Contributor Author

I added back the assertion to the sass-spec to see if adding that parameter fixes the browser failure.

Comment on lines +19 to +20
getJSClass(SassMixin(Callable('f', '', (_) => sassNull)))
.injectSuperclass(jsClass);
Copy link
Contributor

@ntkme ntkme Oct 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this does not make much sense. If I understand it correctly the reason we have this for Sass Function type is to allow the "JS" type to inherit the prototype of dart-converted-JS type? If so here the argument passed into SassMixin (the dart type) should be some argument necessary to construct an actual Mixin object.

@nex3 I don't fully understand how the JS-interop works so please correct me if I'm wrong.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind. Looks like Mixin just takes AsyncCallable so this is probably fine.

@connorskees
Copy link
Contributor Author

If possible, I would like for the first class mixin PRs to merge quite soon -- after this week I will have significantly less time to work outside of work.

@nex3
Copy link
Contributor

nex3 commented Oct 4, 2023

It's not clear to me why the instanceof check isn't working in a browser environment. Injecting the superclass should make it respond to instanceof. You might need to load it up yourself in a browser and poke around there to see where the disconnect is between what should be happening and what is.

@connorskees
Copy link
Contributor Author

connorskees commented Oct 4, 2023

@nex3
Copy link
Contributor

nex3 commented Oct 4, 2023

Jest does have weird instanceof errors, but we don't use Jest in the browser. That also wouldn't explain why the instanceof check fails for SassMixin but succeeds for other Value subtypes.

@connorskees
Copy link
Contributor Author

The most recent error is interesting: Error: Right-hand side of 'instanceof' is not an object. This would imply to me SassMixin imported from 'sass' in the browser is undefined (or something else??).

@ntkme
Copy link
Contributor

ntkme commented Oct 5, 2023

@connorskees I think I found the root cause: we're missing ESM export here:

pkg.jsEsmExports.value = {
'compile',
'compileAsync',
'compileString',
'compileStringAsync',
'Logger',
'SassArgumentList',
'SassBoolean',
'SassCalculation',
'CalculationOperation',
'CalculationInterpolation',
'SassColor',
'SassFunction',
'SassList',
'SassMap',
'SassNumber',
'SassString',

Node runs the CJS entrypoint but browser runs the ESM entrypoint...

@connorskees
Copy link
Contributor Author

Nice find! Thank you -- that would have been annoying to find otherwise.

@nex3
Copy link
Contributor

nex3 commented Oct 5, 2023

I wonder if it would be possible to add a conformance check for that...

@nex3
Copy link
Contributor

nex3 commented Oct 5, 2023

All right, looks like everything is passing but sass/embedded-host-node#253. Once sass/embedded-host-node#255 lands, I'll merge these all in and we should be good to go. Thanks for the hard work, @connorskees!

@nex3 nex3 merged commit ce545c2 into sass:main Oct 5, 2023
44 checks passed
jgerigmeyer added a commit to oddbird/dart-sass that referenced this pull request Oct 12, 2023
* feature.color-4: (30 commits)
  Update for `lch()` tests (sass#2108)
  Add support for relative color syntax (sass#2112)
  Update for `oklab()` tests (sass#2094)
  Poke CI
  Cut a release (sass#2107)
  Implement first class mixins (sass#2073)
  Fix a race condition preventing embedded compiler to shutdown after a protocol error (sass#2106)
  Switch to the GitHub-hosted MacOS ARM64 runner (sass#2103)
  Update the version of Sass used by the website on release (sass#2102)
  Bump actions/checkout from 3 to 4 (sass#2088)
  Bump docker/setup-qemu-action from 2 to 3 (sass#2089)
  Implement support for the relative color syntax of CSS Color 5 (sass#2098)
  Rephrase errors for numbers that must be unitless or % (sass#2101)
  Forbid LLM contributions (sass#2100)
  Update protocol-version during embedded-host-node release (sass#2097)
  Deprecate Deprecation.calcInterp (sass#2096)
  Avoid useless allocations for interpolations without maps (sass#2095)
  Fix an error during embedded compiler shutdown (sass#2092)
  Cut a release (sass#2090)
  Expose the containing URL to importers under some circumstances (sass#2083)
  ...
@@ -418,6 +418,19 @@ final class _EvaluateVisitor
});
}, url: "sass:meta"),

BuiltInCallable.function("module-mixins", r"$module", (arguments) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nex3 is it expected that those functions are exposed as global aliases as well and not just as module functions or is it a mistake ? The spec PR does not mention those aliases).

The metaFunctions variable defined here is not split between local and global lists (probably because when it was introduced, there were no local-only functions).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that metaMixins below is local-only (there is no global aliases for those mixins)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, they aren't expected to be exposed globally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement first-class mixins
4 participants