Skip to content
This repository has been archived by the owner on Feb 4, 2025. It is now read-only.

Add macro metadata dart_model types and converter. #118

Merged
merged 1 commit into from
Oct 25, 2024
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
286 changes: 182 additions & 104 deletions .github/workflows/dart.yml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pkgs/_analyzer_cfe_macros/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:dart_flutter_team_lints/analysis_options.yaml
413 changes: 413 additions & 0 deletions pkgs/_analyzer_cfe_macros/lib/metadata_converter.dart

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions pkgs/_analyzer_cfe_macros/mono_pkg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
sdk:
# Only "pubspec" for when using SDK via a hash reference for latest
# `_fe_analyzer_shared`.
- pubspec

stages:
- analyze_and_format:
- analyze: --fatal-infos .
- format:
sdk:
- dev
- unit_test:
- test: --test-randomize-ordering-seed=random
os:
- linux
- windows
15 changes: 15 additions & 0 deletions pkgs/_analyzer_cfe_macros/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: _analyzer_cfe_macros
publish-to: none
description: Macro support for the analyzer and CFE.
resolution: workspace

environment:
sdk: ^3.7.0-39.0.dev

dependencies:
_fe_analyzer_shared: any
dart_model: any

dev_dependencies:
dart_flutter_team_lints: ^3.0.0
test: ^1.25.0
62 changes: 62 additions & 0 deletions pkgs/_analyzer_cfe_macros/test/metadata_converter_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:_analyzer_cfe_macros/metadata_converter.dart';
import 'package:_fe_analyzer_shared/src/metadata/ast.dart';
import 'package:test/test.dart';

void main() {
test('converts with unions', () {
final invocation = MethodInvocation(DoubleLiteral('1.23'), 'round', [], []);

expect(convert<Object>(invocation), <String, Object?>{
'receiver': {
'type': 'DoubleLiteral',
'value': {'text': '1.23'}
},
'name': 'round',
'typeArguments': [],
'arguments': [],
});
});

test('converts with enums', () {
final expression = BinaryExpression(
DoubleLiteral('1.23'), BinaryOperator.minus, DoubleLiteral('1.24'));

expect(convert<Object>(expression), <String, Object?>{
'left': {
'type': 'DoubleLiteral',
'value': {'text': '1.23'}
},
'operator': 'minus',
'right': {
'type': 'DoubleLiteral',
'value': {'text': '1.24'}
}
});
});

test('converts with lists', () {
final invocation = MethodInvocation(DoubleLiteral('1.23'), 'round', [],
[PositionalArgument(IntegerLiteral('4'))]);

expect(convert<Object>(invocation), <String, Object?>{
'receiver': {
'type': 'DoubleLiteral',
'value': {'text': '1.23'}
},
'name': 'round',
'typeArguments': [],
'arguments': [
{
'expression': {
'type': 'IntegerLiteral',
'value': {'text': '4'}
}
}
]
});
});
}
Loading