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

(request) Object destructuring #4

Open
JaRoLoz opened this issue Apr 10, 2023 · 3 comments
Open

(request) Object destructuring #4

JaRoLoz opened this issue Apr 10, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@JaRoLoz
Copy link

JaRoLoz commented Apr 10, 2023

Hi, it would be nice if this syntax could be implemented:

function someFunction({ prop1, prop2 })
    print(prop1, prop2)
end
@MrFreex MrFreex added the enhancement New feature or request label Apr 11, 2023
@XenoS-ITA
Copy link
Member

You can already do an object destruction but not in the parameters, example:

function someFunction(obj)
    prop1, prop2 = ...obj
    print(prop1, prop2)
end

However, we could also add the version you mentioned, have you seen similar syntax yet? (like a documentation of some languages or something)
@MrFreex what do you think?

@JaRoLoz
Copy link
Author

JaRoLoz commented Apr 21, 2023

I've been searching for any documentation on how to implement it, but haven't found anything. What i've came up with is just replacing the destructured object in the parameters with a dummy parameter name, such as __parameter, and then replacing the used propperties of the object inside the function with __parameter.property. Example:

# before preprocessing
function myFunction({ prop1, prop2 })
    print(prop1, prop2)
end
# after preprocessing
function myFunction(__parameter)
    print(__parameter.prop1, __parameter,prop2)
end

@XenoS-ITA
Copy link
Member

that method could be quite a challenge since leap works on regex, it does not use AST or parser, so it is quite complicated to do it with regex.

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

No branches or pull requests

3 participants