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

Fixes to CLI and parser #82

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions .github/workflows/performance-and-size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ jobs:
env:
CARGO_PROFILE_RELEASE_DEBUG: true

- name: Run parser (and stringer) performance
- name: Download files
run: |
curl -O https://gist.githubusercontent.com/kaleidawave/5dcb9ec03deef1161ebf0c9d6e4b88d8/raw/03156048e214af0ceee4005ba8b86f96690dcbb2/demo.ts > demo.ts

curl https://esm.sh/v128/[email protected]/es2022/react-dom.mjs > react.js

- name: Run parser, minfier, stringer performance
shell: bash
run: |
curl https://esm.sh/v128/[email protected]/es2022/react-dom.mjs > react.js

Expand All @@ -42,18 +49,19 @@ jobs:
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY

- name: Run checker performance
shell: bash
if: false
run: |
curl -O https://gist.githubusercontent.com/kaleidawave/5dcb9ec03deef1161ebf0c9d6e4b88d8/raw/03156048e214af0ceee4005ba8b86f96690dcbb2/demo.ts > demo.ts

echo "### Output">> $GITHUB_STEP_SUMMARY
echo "\`\`\`shell">> $GITHUB_STEP_SUMMARY
./target/release/ezno check demo.ts &>> $GITHUB_STEP_SUMMARY
./target/release/ezno check demo.ts >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY

echo "### Hyperfine">> $GITHUB_STEP_SUMMARY
echo "\`\`\`shell">> $GITHUB_STEP_SUMMARY
hyperfine './target/release/ezno check demo.ts' >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY

- name: Print (linux) binary size
run: |
echo "Binary is $(stat -c %s ./target/release/ezno) bytes" >> $GITHUB_STEP_SUMMARY
1 change: 0 additions & 1 deletion .github/workflows/pull-request-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: PR Checker

on:
pull_request_target:
branches: [main]
types: [opened]

jobs:
Expand Down
2 changes: 1 addition & 1 deletion checker/src/synthesis/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ pub(super) fn synthesise_expression<T: crate::ReadFromFS>(
SpecialOperators::InExpression { .. } => todo!(),
SpecialOperators::InstanceOfExpression { .. } => todo!(),
},
Expression::DynamicImport { path, position } => todo!(),
Expression::DynamicImport { .. } => todo!(),
Expression::IsExpression(is_expr) => {
Instance::RValue(synthesise_is_expression(is_expr, environment, checking_data))
}
Expand Down
73 changes: 41 additions & 32 deletions checker/src/synthesis/hoisting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,16 @@ pub(crate) fn hoist_statements<T: crate::ReadFromFS>(
environment.new_alias(&alias.type_name.name, to, &mut checking_data.types);
}
parser::Declaration::Import(import) => {
let kind = match &import.kind {
parser::declarations::import::ImportKind::Parts(parts) => {
let kind = match &import.items {
parser::declarations::import::ImportedItems::Parts(parts) => {
crate::behavior::modules::ImportKind::Parts(
parts.iter().filter_map(|item| import_part_to_name_pair(item)),
parts
.iter()
.flatten()
.filter_map(|item| import_part_to_name_pair(item)),
)
}
parser::declarations::import::ImportKind::All { under } => match under {
parser::declarations::import::ImportedItems::All { under } => match under {
VariableIdentifier::Standard(under, position) => {
crate::behavior::modules::ImportKind::All {
under,
Expand All @@ -97,9 +100,6 @@ pub(crate) fn hoist_statements<T: crate::ReadFromFS>(
}
VariableIdentifier::Cursor(_, _) => todo!(),
},
parser::declarations::import::ImportKind::SideEffect => {
crate::behavior::modules::ImportKind::SideEffect
}
};
let default_import = import.default.as_ref().and_then(|default_identifier| {
match default_identifier {
Expand All @@ -109,47 +109,54 @@ pub(crate) fn hoist_statements<T: crate::ReadFromFS>(
VariableIdentifier::Cursor(..) => None,
}
});
environment.import_items(
&import.from,
import.position.clone(),
default_import,
kind,
checking_data,
false,
);
if let Some(path) = import.from.get_path() {
environment.import_items(
path,
import.position.clone(),
default_import,
kind,
checking_data,
false,
);
}
}
parser::Declaration::Export(export) => {
if let ExportDeclaration::Variable { exported, position } = &export.on {
// Imports & types
match exported {
Exportable::ImportAll { r#as, from } => {
environment.import_items::<iter::Empty<_>, _, _>(
from,
position.clone(),
None,
match r#as {
if let Some(path) = from.get_path() {
let kind = match r#as {
Some(VariableIdentifier::Standard(name, pos)) => {
ImportKind::All { under: name, position: pos.clone() }
}
Some(VariableIdentifier::Cursor(_, _)) => todo!(),
None => ImportKind::Everything,
},
checking_data,
true,
);
};
environment.import_items::<iter::Empty<_>, _, _>(
path,
position.clone(),
None,
kind,
checking_data,
true,
);
}
}
Exportable::ImportParts { parts, from } => {
let parts =
parts.iter().filter_map(|item| export_part_to_name_pair(item));

environment.import_items(
from,
position.clone(),
None,
crate::behavior::modules::ImportKind::Parts(parts),
checking_data,
true,
);
if let Some(path) = from.get_path() {
environment.import_items(
path,
position.clone(),
None,
crate::behavior::modules::ImportKind::Parts(parts),
checking_data,
true,
);
}
}
Exportable::TypeAlias(alias) => {
let to = synthesise_type_annotation(
Expand Down Expand Up @@ -386,6 +393,7 @@ fn import_part_to_name_pair(item: &parser::declarations::ImportPart) -> Option<N
value: match alias {
parser::declarations::ImportExportName::Reference(item)
| parser::declarations::ImportExportName::Quoted(item, _) => item,
_ => todo!(),
},
r#as: &name,
position: position.clone(),
Expand Down Expand Up @@ -417,6 +425,7 @@ pub(super) fn export_part_to_name_pair(
r#as: match alias {
parser::declarations::ImportExportName::Reference(item)
| parser::declarations::ImportExportName::Quoted(item, _) => item,
_ => todo!(),
},
position: position.clone(),
})
Expand Down
2 changes: 1 addition & 1 deletion checker/src/synthesis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub(super) fn property_key_as_type<S: ContextType, P: parser::property_key::Prop
types: &mut TypeStore,
) -> TypeId {
match property_key {
PropertyKey::StringLiteral(value, _) | PropertyKey::Ident(value, _, _) => {
PropertyKey::StringLiteral(value, ..) | PropertyKey::Ident(value, _, _) => {
types.new_constant_type(Constant::String(value.clone()))
}
PropertyKey::NumberLiteral(number, _) => {
Expand Down
2 changes: 1 addition & 1 deletion checker/src/synthesis/type_annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub(super) fn synthesise_type_annotation<T: crate::ReadFromFS>(
CommonTypes::Number => TypeId::NUMBER_TYPE,
CommonTypes::Boolean => TypeId::BOOLEAN_TYPE,
},
TypeAnnotation::StringLiteral(value, _) => {
TypeAnnotation::StringLiteral(value, ..) => {
checking_data.types.new_constant_type(Constant::String(value.clone()))
}
TypeAnnotation::NumberLiteral(value, _) => {
Expand Down
2 changes: 1 addition & 1 deletion parser/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
Visitable,
};

#[derive(Debug, Clone, PartialEq, Visitable, get_field_by_type::GetFieldByType)]
#[derive(Debug, Clone, PartialEq, Visitable, get_field_by_type::GetFieldByType, EnumFrom)]
#[get_field_by_type_target(Span)]
#[cfg_attr(feature = "self-rust-tokenize", derive(self_rust_tokenize::SelfRustTokenize))]
#[cfg_attr(feature = "serde-serialize", derive(serde::Serialize))]
Expand Down
57 changes: 14 additions & 43 deletions parser/src/declarations/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::{
};

use super::{
variable::VariableDeclaration, ClassDeclaration, ImportExportName, InterfaceDeclaration,
StatementFunction, TypeAlias,
variable::VariableDeclaration, ClassDeclaration, ImportExportName, ImportLocation,
InterfaceDeclaration, StatementFunction, TypeAlias,
};

use get_field_by_type::GetFieldByType;
Expand Down Expand Up @@ -39,8 +39,8 @@ pub enum Exportable {
Interface(InterfaceDeclaration),
TypeAlias(TypeAlias),
Parts(Vec<ExportPart>),
ImportAll { r#as: Option<VariableIdentifier>, from: String },
ImportParts { parts: Vec<ExportPart>, from: String },
ImportAll { r#as: Option<VariableIdentifier>, from: ImportLocation },
ImportParts { parts: Vec<ExportPart>, from: ImportLocation },
}

impl ASTNode for ExportDeclaration {
Expand Down Expand Up @@ -74,24 +74,8 @@ impl ASTNode for ExportDeclaration {
None
};
reader.expect_next(TSXToken::Keyword(TSXKeyword::From))?;
let token = reader.next().ok_or_else(parse_lexing_error)?;
let (end, from) = match token {
Token(
TSXToken::DoubleQuotedStringLiteral(from)
| TSXToken::SingleQuotedStringLiteral(from),
start,
) => {
let span = start.with_length(from.len() + 2);
(span, from)
}
token => {
let position = token.get_span();
return Err(ParseError::new(
crate::ParseErrors::ExpectedStringLiteral { found: token.0 },
position,
));
}
};
let (from, end) =
ImportLocation::from_token(reader.next().ok_or_else(parse_lexing_error)?)?;
Ok(ExportDeclaration::Variable {
exported: Exportable::ImportAll { r#as, from },
position: start.union(end),
Expand Down Expand Up @@ -154,23 +138,9 @@ impl ASTNode for ExportDeclaration {
)?;
// Know this is 'from' from above
let _ = reader.next().unwrap();
let (end, from) = match reader.next().ok_or_else(parse_lexing_error)? {
Token(
TSXToken::DoubleQuotedStringLiteral(from)
| TSXToken::SingleQuotedStringLiteral(from),
start,
) => {
let span = start.with_length(from.len() + 2);
(span, from)
}
token => {
let position = token.get_span();
return Err(ParseError::new(
crate::ParseErrors::ExpectedStringLiteral { found: token.0 },
position,
));
}
};
let (from, end) = ImportLocation::from_token(
reader.next().ok_or_else(parse_lexing_error)?,
)?;
Ok(Self::Variable {
exported: Exportable::ImportParts { parts, from },
position: start.union(end),
Expand All @@ -195,7 +165,7 @@ impl ASTNode for ExportDeclaration {
));
}
}
Token(TSXToken::Keyword(kw), _) if kw.is_function_heading() => {
Token(TSXToken::Keyword(kw), _) if kw.is_in_function_header() => {
let function_declaration = StatementFunction::from_reader(reader, state, options)?;
let position = start.union(function_declaration.get_position());
Ok(Self::Variable {
Expand Down Expand Up @@ -264,7 +234,7 @@ impl ASTNode for ExportDeclaration {
buf.push(' ');
}
buf.push_str("from \"");
buf.push_str(from);
from.to_string_from_buffer(buf);
buf.push('"');
}
Exportable::ImportParts { parts, from } => {
Expand All @@ -281,7 +251,7 @@ impl ASTNode for ExportDeclaration {
buf.push('}');
options.add_gap(buf);
buf.push_str("from \"");
buf.push_str(from);
from.to_string_from_buffer(buf);
buf.push('"');
}
}
Expand Down Expand Up @@ -335,7 +305,7 @@ impl ASTNode for ExportPart {
{
reader.next();
let token = reader.next().ok_or_else(parse_lexing_error)?;
let (alias, end) = ImportExportName::from_token(token)?;
let (alias, end) = ImportExportName::from_token(token, state)?;
let position = pos.union(end);
Self::NameWithAlias { name, alias, position }
} else {
Expand Down Expand Up @@ -371,6 +341,7 @@ impl ASTNode for ExportPart {
buf.push_str(alias);
buf.push(q.as_char());
}
ImportExportName::Cursor(_) => {}
}
}
ExportPart::PrefixComment(comment, inner, _) => {
Expand Down
Loading
Loading