From 211275ab496811218bcee57c0357dd1433b5250d Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 14 Apr 2020 18:24:19 +0200 Subject: [PATCH] fmt: always use import() syntax --- vlib/v/fmt/fmt.v | 28 ++++++++++----------- vlib/v/fmt/tests/import_single_expected.vv | 4 ++- vlib/v/fmt/tests/missing_import_expected.vv | 4 ++- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 8ee20ea50b..feb6e15537 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -98,28 +98,28 @@ fn (f mut Fmt) mod(mod ast.Module) { } fn (f mut Fmt) imports(imports []ast.Import) { - if f.did_imports { + if f.did_imports || imports.len == 0 { return } - f.did_imports = true // f.import_pos = f.out.len + f.did_imports = true + /* if imports.len == 1 { imp_stmt_str := f.imp_stmt_str(imports[0]) f.out_imports.writeln('import ${imp_stmt_str}\n') } else if imports.len > 1 { - f.out_imports.writeln('import (') - // f.indent++ - for imp in imports { - if !(imp.mod in f.used_imports) { - // TODO bring back once only unused imports are removed - // continue - } - f.out_imports.write('\t') - f.out_imports.writeln(f.imp_stmt_str(imp)) +*/ + f.out_imports.writeln('import (') + for imp in imports { + if !(imp.mod in f.used_imports) { + // TODO bring back once only unused imports are removed + // continue } - // f.indent-- - f.out_imports.writeln(')\n') + f.out_imports.write('\t') + f.out_imports.writeln(f.imp_stmt_str(imp)) } + f.out_imports.writeln(')\n') + // } } fn (f Fmt) imp_stmt_str(imp ast.Import) string { @@ -555,7 +555,7 @@ fn (f mut Fmt) expr(node ast.Expr) { ast.MapInit { if it.keys.len == 0 { if it.value_type == 0 { - f.write('map[string]int') // TODO + f.write('map[string]int') // TODO return } f.write('map[string]') diff --git a/vlib/v/fmt/tests/import_single_expected.vv b/vlib/v/fmt/tests/import_single_expected.vv index 6dd15c16de..31184f6790 100644 --- a/vlib/v/fmt/tests/import_single_expected.vv +++ b/vlib/v/fmt/tests/import_single_expected.vv @@ -1,4 +1,6 @@ -import os +import ( + os +) fn main() { } diff --git a/vlib/v/fmt/tests/missing_import_expected.vv b/vlib/v/fmt/tests/missing_import_expected.vv index c463392943..3e9a2f867c 100644 --- a/vlib/v/fmt/tests/missing_import_expected.vv +++ b/vlib/v/fmt/tests/missing_import_expected.vv @@ -1,4 +1,6 @@ -import time +import ( + time +) fn main() { println(time.now())